Reputation: 29571
{% if None == False %}
abc
{% endif %}
The above code, strangely my template displayed abc
. Any explanation?
Upvotes: 3
Views: 195
Reputation: 29571
Jason Culverhouse provided the answer in another similar question i asked.
False and None are treat as variables, instead of constants. If the variables ore not found in the context dictionary, there are resolved to None.
Upvotes: 3
Reputation: 4329
For now It seem like you will have to create your own template filter as was suggested in this post
Upvotes: 0
Reputation: 9110
This is just the way Python resolves 'truth' for comparison between different types.
See the docs. "None" is considered False.
http://docs.python.org/library/stdtypes.html#truth-value-testing
Edit: as below, the python console does not confirm this behaviour, so, I am also surprised. -1 to me!
Upvotes: 1
Reputation: 42769
Bizarre. In regular python,
if None == False:
# this will not run
print "abc"
File a bug on Django. :)
Upvotes: 3