Reputation: 1755
Maybe it's a little bit stupid question, but I didn't find an answer. Is there any way to use increased/decreased variables in django templates?
e.g.{{ some_variable + 1 }}
Upvotes: 5
Views: 3795
Reputation: 2419
Inside for loop use forloop.counter that will automatically increase the counter till the records.
{% for a in object_list %}
{{ forloop.counter }}
{% endfor %}
Upvotes: 1
Reputation: 599490
There's a built-in add
filter:
{{ some_variable|add:"1" }}
Upvotes: 10
Reputation: 535
One way of doing this is by using a django template filter.
https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters
def inc(value):
return value+1
and then:
{{ some_variable|inc }}
Upvotes: 1