Retspen
Retspen

Reputation: 21

Loop in Django tempates

I have two variables, name = ["Fedora", "Ubuntu"] and state = {"Fedora": "up", "Ubuntu": "down"}.

How do 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.

Upvotes: 2

Views: 97

Answers (1)

Gabriel Ross
Gabriel Ross

Reputation: 5198

Try this:

{% for n,s in state.items %}
{{ n }}: {{ s }}<br>
{% endfor %}

Upvotes: 4

Related Questions