简体   繁体   English

Django模板不适用于布尔值?

[英]Django template doesn't work with booleans?

I have the following template that only should activate when test is true . 我有以下模板,只有在testtrue时才会激活。

{% if test %}
  <h1>The value of test was {{ test }} </h1>
{% endif %}

In views.py, test is being set to false . 在views.py中, test被设置为false However, in the resulting html, I see the phrase that The value of test was false . 但是,在生成的html中,我看到了The value of test was false的短语。 How can I instead only get this template to activate when test is true ? test true时,我怎样才能让这个模板激活?

Pass the Boolean False instead of the string "false" . 传递布尔值False而不是字符串"false" You can tell which one you're passing by seeing whether {{ test }} is being displayed as False , in which case it's a boolean, or false , in which case you're passing a string. 您可以通过查看{{ test }}是否显示为False来判断您传递的是哪一个,在这种情况下,它是布尔值,或者为false ,在这种情况下,您传递的是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM