views:

272

answers:

1

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?

+2  A: 

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.

muratgu
Perhaps they are not related. However, the way I understood the parameters to the {% if %} tag, is that it gets passed to the resolve() method with a context. If it resolves to a variable name, the variable name gets assigned to it. Else, it interprets it as a literal (True being valid literal)
True is not a valid literal in a template by default. (Just for sanity I tested it locally to confirm it)
muratgu