Logical comparison in a Django template

I have a boolean field in my Django model, like

reminder = models.BooleanField() 

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

I do so

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

But, unfortunately, the above code does not give the expected result. I want to delete everything reminder = False Please help me, what can I do wrong here.

+9
django
source share
2 answers

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

 {% if x.reminder %} 

or

 {% if x.reminder == True %} 
+11
source share

Just use this:

 {% if x.reminder %} 

This (without quotes) works with django 1.5, but it is superfluous.

 {% if x.reminder == True %} 

https://docs.djangoproject.com/en/dev/releases/1.5/#minor-features

The template engine now interprets True, False, and None as the corresponding Python objects.

+5
source share

All Articles