How can I distinguish between None and False in django templates?
{% if x %}
True
{% else %}
None and False - how can I split this case?
{% endif %}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Every Django template context contains
True,FalseandNone. For Django 1.10 and later, you can do the following:Django 1.9 and earlier do not support the
isoperator in theiftag. Most of the time, it is ok to use{% if x == None %}instead.With Django 1.4 and earlier, you do not have access to
True,FalseandNonein the template context, You can use theyesnofilter instead.In the view:
In the template:
Result: