title: Can I compare a template variable to an integer in Django/App Engine templates?
body: <p>Using Django templates in Google App Engine (on Python), is it possible to compare a template variable to an integer in an <code>{% if %}</code> block?</p>
  
  <p>views.py:</p>
  
  <pre><code>class MyHandler(webapp.RequestHandler):
      def get(self):
          foo_list = db.GqlQuery(...)
          ...
          template_values['foos'] = foo_list
          template_values['foo_count'] = len(foo_list)
          handler.response.out.write(template.render(...))
  </code></pre>
  
  <p>My template:</p>
  
  <pre><code>{% if foo_count == 1 %}
       There is one foo.
  {% endif %}
  </code></pre>
  
  <p>This blows up with <code>'if' statement improperly formatted</code>.</p>
  
  <p>What I was attempting to do in my template was build a simple if/elif/else tree to be grammatically correct to be able to state</p>
  
  <pre><code>#foo_count == 0:
  There are no foos.
  
  #foo_count == 1:
  There is one foo.
  
  #else:
  There are {{ foos|length }} foos.
  </code></pre>
  
  <p>Browsing the Django template documents (<a href="http://www.djangoproject.com/documentation/templates/" rel="noreferrer">this link</a> provided <a href="http://code.google.com/appengine/docs/python/gettingstarted/templates.html" rel="noreferrer">in the GAE documentation</a> appears to be for versions of Django far newer than what is supported on GAE), it appears as if I can only actually use boolean operators (if in fact boolean operators are supported in this older version of Django) with strings or other template variables.</p>
  
  <p>Is it not possible to compare variables to integers or non-strings with Django templates?</p>
  
  <p>I'm sure there is an easy way to workaround this - built up the message string on the Python side rather than within the template - but this seems like such a simple operation you ought to be able to handle in a template. </p>
  
  <p>It sounds like I should be switching to a more advanced templating engine, but as I am new to Django (templates or any part of it), I'd just like some confirmation first. </p>