views:

23

answers:

1

i want to compare do simple math in django template

like {% forloop.counter > 5 %} {% endfor %}

how do i achieve this?

A: 

You can do that with the if tag in Django 1.2

{% for blip in blah %}
    {% if forloop.counter > 5 %}
    {# Do somthing #}
    {% endif %}
{% endfor %}

If you are still using an earlier version of Django then you can check out the smart if tag on djangosnippets: http://djangosnippets.org/snippets/1350/

Mark Lavin
I am using Django .96 with google app engine and it does not work there
demos
Sorry. I see now the snippet is for Django 1.0 or higher.
Mark Lavin