S
S
Stanislav2019-05-24 14:29:31
Django
Stanislav, 2019-05-24 14:29:31

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'}
}

Can't make a withdrawal
<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

1 answer(s)
V
Vadim Shatalov, 2019-05-24
@Chebaa

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 question

Ask a Question

731 491 924 answers to any question