[英]Django template doesn't work with booleans?
I have the following template that only should activate when test
is true
. 我有以下模板,只有在
test
为true
时才会激活。
{% 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.