[Django]-Loop through a defaultdict(list) structure in a django template

3👍

You should loop through .items() of the dictionary to get both object and the list in hand at each iteration:

{% for obj, things in my_dict.items %}
    {{obj.somefield}}

    {% for thing in things %}
        {{thing.somefield}}
    {% endfor %}

{% endfor %}

Leave a comment