[Fixed]-Boolean comparison in django template

20👍

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

{% if x.reminder %}

or

{% if x.reminder == True %}

6👍

Just use this:

{% if x.reminder %}

This (without quotes) works since django 1.5, but it’s 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.

Leave a comment