[英]How to iterate over the next element in the map in the inner loop, while coming from the next element of the map in the outer loop?
[英]How to iterate over the next element in a tuple in Django?
說我有一個元組:
a = (1, 2, 3)
現在我想做點什么:
for i in a:
if i == 1:
print a[1]
我的意思是如果第一個元素是1我想立即提取第二個元素而不進入for循環的另一個迭代。
我怎么能在django模板中這樣做?
這確實有效的同樣的事情,你的Python代碼,假設你已經通過a
給模板上下文:
{% for i in a %}
{% if i == 1 %}
{{ a.1 }}
{% endif %}
{% endfor %}
{% for i in a %}{% ifequal i 1 %}{{ a.1 }}{% endifequal %}{% endfor %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.