擅长:python、mysql、java
<p>如文件所述:</p>
<blockquote>
<p>Please note that assignments in loops will be cleared at the end of
the iteration and cannot outlive the loop scope.</p>
</blockquote>
<p>但是从2.10版开始,您可以使用名称空间:</p>
<pre><code> {% set ns = namespace(foo=false) %}
{% for item in items %}
{% set ns.foo = True %}
{% if ns.foo %} Ok(1)! {% endif %}
{% endfor %}
{% if ns.foo %} Ok(2)! {% endif %}
</code></pre>