开发者

Loop in Django tempates

开发者 https://www.devze.com 2023-03-30 15:55 出处:网络
I have two variables, name = [\"Fedora\", \"Ubuntu\"] and state = {\"Fedora\": \"up\", \"Ubuntu\": \"down\"}.

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

精彩评论

暂无评论...
验证码 换一张
取 消