【发布时间】:2018-05-11 13:11:18
【问题描述】:
有没有办法将比较中的逻辑值分配给当前上下文中的变量?
我试过了:
{% with hidden=forloop.counter > 4 %}
{% include "path/to/template.html" %}
{% endwith %}
它不起作用,因为这会导致语法错误。但也许只是一种我不知道的语法?
到目前为止,我做了这样的事情:
{% if forloop.counter > 4 %}
{% with hidden=True %}
{% include "path/to/template.html" %}
{% endwith %}
{% else %}
{% include "path/to/template.html" %}
{% endif %}
而且它有效,但对我来说它看起来很脏。
【问题讨论】:
标签: django templates with-statement