问题
i want to compare do simple math in django template
like {% forloop.counter > 5 %} {% endfor %}
how do i achieve this?
回答1:
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/
来源:https://stackoverflow.com/questions/3148350/math-comparison-operating-in-django-templates