How do I check if a variable is False using Django template syntax?
{% if myvar == False %}
Doesn't seem to work.
Note that I very specifically want to check if it has the Python value False
. This variable could be an empty array too, which is not what I want to check for.
For posterity, I have a few NullBooleanField
s and here's what I do:
To check if it's True
:
{% if variable %}True{% endif %}
To check if it's False
(note this works because there's only 3 values -- True/False/None):
{% if variable != None %}False{% endif %}
To check if it's None
:
{% if variable == None %}None{% endif %}
I'm not sure why, but I can't do variable == False
, but I can do variable == None
.