Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 31765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:39:23+00:00 2026-05-10T13:39:23+00:00

I have a tree structure in memory that I would like to render in

  • 0

I have a tree structure in memory that I would like to render in HTML using a Django template.

class Node():   name = 'node name'   children = [] 

There will be some object root that is a Node, and children is a list of Nodes. root will be passed in the content of the template.

I have found this one discussion of how this might be achieved, but the poster suggests this might not be good in a production environment.

Does anybody know of a better way?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:39:24+00:00Added an answer on May 10, 2026 at 1:39 pm

    I think the canonical answer is: ‘Don’t’.

    What you should probably do instead is unravel the thing in your view code, so it’s just a matter of iterating over (in|de)dents in the template. I think I’d do it by appending indents and dedents to a list while recursing through the tree and then sending that ‘travelogue’ list to the template. (the template would then insert <li> and </li> from that list, creating the recursive structure with ‘understanding’ it.)

    I’m also pretty sure recursively including template files is really a wrong way to do it…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tree data structure that is L levels deep each node has
I have a sort of tree structure that represent a hierarchy of layers in
I have a table in SQL server that has the normal tree structure of
I have tree control object created using CTreeCtrl MFC class. The tree control needs
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
Assuming I have a tree structure UL --LI ---INPUT (checkbox) And I want to
I have a table in my database which stores a tree structure. Here are
I have a very large point cloud (> 100000 points) that I'd like to
I have tree tables, Customer, Invoice and InvoiceRow with the standard relations. These I
I have a tree representation of pages in a CMS application. I understand how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.