Answer the question
In order to leave comments, you need to log in
How to display a nested dictionary as a sorted list in Django template?
Greetings!
Nested View Dictionary
data = {
'Item2': {'weight': 200, 'parent': 'root'},
'Item1': {'weight': 100, 'parent': 'root'},
'SubItem1': {'weight': 100, 'parent': 'Item1'},
'SubItem1.3': {'weight': 300, 'parent': 'SubItem1'},
'SubItem1.2': {'weight': 200, 'parent': 'SubItem1'},
'SubItem1.1': {'weight': 100, 'parent': 'SubItem1'}
}
<ul>
<li>
Item1
<ul>
<li>
SubItem1
<ul>
<li>SubItem1.1</li>
<li>SubItem1.2</li>
<li>SubItem1.3</li>
</ul>
</li>
</ul>
</li>
<li>Item2</li>
</ul>
Answer the question
In order to leave comments, you need to log in
You should not put complex logic into templates
. In your case, I would use custom tags
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question