![](/img/trans.png)
[英]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.