How do I check if a variable is False using Django template syntax?
{% if myvar == False %}
Doesn\'t seem to work.
This is far easier to check in Python (i.e. your view code) than in the template, because the Python code is simply:
myvar is False
Illustrating:
>>> False is False
True
>>> None is False
False
>>> [] is False
False
The problem at the template level is that the template if
doesn't parse is
(though it does parse in
). Also, if you don't mind it, you could try to patch support for is
into the template engine; base it on the code for ==
.