[Django]-Django template strange behaviour

3👍

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.

👤goh

3👍

Bizarre. In regular python,

if None == False:
    # this will not run
    print "abc"

File a bug on Django. 🙂

👤Leopd

1👍

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!

👤laher

0👍

For now It seem like you will have to create your own template filter as was suggested in this post

0👍

Alternatively, you can do if not None.

Leave a comment