Loop in Django tempates
I have two variables, name = ["Fedora", "Ubuntu"]
and state = {"Fedora": "up", "Ubuntu": "down"}
.
How d开发者_Go百科o I display this data in a loop?
{% for s in state %}
{% for n in state %}
{{ n }} {{ s }}
{% endfor %}
{% endfor %}
Variable "n" is displayed four times instead of two times.
Try this:
{% for n,s in state.items %}
{{ n }}: {{ s }}<br>
{% endfor %}
精彩评论