Faizalprbw
Faizalprbw

Reputation: 529

How to use variable from looping as dictionary key in Django template?

assumed that i have return a dictionary like this in my views or template_tags :

data = {key1:value1,key2:value2,......,keyn:valuen}

how can i generate something like this in my html template ?

value1
value2
value3
.
.
.
valuen

This is what i've got as far as i know :

 {% for i in data %}
 {% for j in data.i %}
 {{ j }} <br>
 {% endfor %}
 {% endfor %}

Upvotes: 0

Views: 165

Answers (1)

dkurzaj
dkurzaj

Reputation: 356

According to this documentation page : https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#for this should work as you wish :

{% for key, value in data.items %}
    {{ value }} <br />
{% endfor %}

Upvotes: 1

Related Questions