[Answer]-How to iterate dictionary objects in template

1👍

You can use dict.items method. In python 2.x better use dict.iteritems instead.

{% for y_key, yr in archives.items %}
    <li>{{ yr.year }} &nbsp;({{ yr.count }})</li>
    {% for m_key, mth in yr.months.items %}
        <li>&nbsp;&nbsp; - {{ mth.month_name }} &nbsp; ({{ mth.count }})</li>
    {% endfor %}
{% endfor %}
👤stalk

Leave a comment