Django模板中的布尔比较 [英] Boolean comparison in django template

查看:136
本文介绍了Django模板中的布尔比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Django模型中有一个布尔字段,例如

I have a boolean field in my Django model like

reminder = models.BooleanField()

现在,我想在某些条件下在django模板中比较此字段。

Now I want to compare this field in my django template in some certain conditions .

我这样做

{% if x.reminder == 'True' %}

但是不幸的是上面的代码并没有给我预期的结果。我想删除所有 reminder = False 请帮助我,我在这里可能做错了什么。

But unfortunately above code is not giving me expected result .I want to remove all reminder = False Please help me what might I am doing wrong here .

推荐答案

您正在比较 x.reminder 转换为名为'True'的字符串,而不是True常量

you are comparing x.reminder to a string named 'True', not the True constant

{% if x.reminder %}

{% if x.reminder == True %}

这篇关于Django模板中的布尔比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆