简体   繁体   中英

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 %}

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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM