开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜