I wonder if there is a way to make a while loop in django (I think that is what I need)?
What I'm trying to do is list n / a ul / li.
The list is generated by a for loop in a for loop. But since some elements in the second loop have more children, I want to iterate or them before and so on until all child nodes are iterated. The only way I've found so far is to have a different loop. But this does not seem to be general and rather repetitive. And I need to know how many โlevelsโ a child has.
Now it looks like this:
<ul> {% for item in items %} <li> {{ item.name }} {% if item.childs %} <ul> {% for child in item.childs %} <li>{{ child.name }}</li> {% endfor %} </ul> {% endif %} </li> {% endfor %} </ul>
Or is there a smarter way to send data to a template? Is it possible to do this with some for / while loop?
.. Fredrick
source share