D
D
Dauren S2016-03-07 11:03:20
Django
Dauren S, 2016-03-07 11:03:20

How to make a loop counter in a django template?

Django. I output a cycle of articles in the template through for.
How to make a counter. Type i. That is, in the for block, there was a variable i inside.
That is, I need to change the class name of the div after 3 cycles.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2016-03-07
@deliro

{{ forloop.counter0 }} - starts from zero
{{ forloop.counter }} - starts from one.

S
sim3x, 2016-03-07
@sim3x

https://docs.djangoproject.com/es/1.9/ref/template...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question