我正在编写基于jinja2模板的应用程序。我试图编写一个设置变量的逻辑。
{% set last_item = none %}
{% for u in users %}
{% if not u.username == user.username%}
{% if g.user.is_bestfriend(u) %}
{% set last_item = 'true' %}
{% endif %}
{% endif %}
{% endfor %}
{{last_item}}
但是在{% endfor %}
之后,last_item
的值再次被设置为None
,而不是True
。有没有办法在jinja2模板中将其设置为True
?