django template iterate dict
{% for key, value in my_dict.items %}
Key: {{ key }} - Value: {{ value }}
{% endfor %}
Explanation:
- {% for key, value in my_dict.items %}
: This line initiates a for loop in Django template. It iterates through the items (key-value pairs) of the my_dict
dictionary.
- Key: {{ key }} - Value: {{ value }}
: Within the loop, this line displays the key and value of each item in the dictionary my_dict
.
- {% endfor %}
: This line marks the end of the for loop block in Django template.