在语句中定义Django变量

时间:2018-01-30 11:38:02

标签: django if-statement django-templates

我想在我的Django模板中定义一个变量,但如果我在语句中设置变量,我就不能再调用它。有没有办法从模板的其他部分调用变量?提前谢谢!

我的意见:

{% if a > 1 %}
   {% with "string_1" as var %}
   {% endwith %}
{% elif a < 1%}
   {% with "string_2" as var %}
   {% endwith %}
{% else %}
   {% with "string_3" as var %}
   {% endwith %}
{% endif %}

{% if var='string_1' %}  #here i want to call the variable again
   <p>This is string_1</p>
{%else%}
   <p>This is not string_1</p>

0 个答案:

没有答案