Django Template if tag not working under FastCGI when checking bool True
-
22-08-2019 - |
Question
I have a strange issue specific to my Django deployment under Python 2.6 + Ubuntu + Apache 2.2 + FastCGI.
If I have a template as such:
{% with True as something %}
{%if something%}
It Worked!!!
{%endif%}
{%endwith%}
it should output the string "It Worked!!!". It does not on my production server with mod_fastcgi.
This works perfectly when I run locally with runserver.
I modified the code to the following to make it work for the sake of expediency, and the problem went away.
{% with "True" as something %}
{%if something%}
It Worked!!!
{%endif%}
{%endwith%}
It seems that the template parser, when running under FastCGI, cannot ascertain Truthiness (or Truthitude)[kudos if you get the reference] of bool variables.
Has anyone seen this? Do you have a solution?
Solution
Hmm... True
is not a valid token in django template language, is it? I have no idea how it worked locally -- unless it's being added to the context with a non-zero value somewhere. Therefore, I think your second problem may not be related to the first one.