I have a basic question, in the Django template language how can you tell if you are at the last loop iteration in a for
loop?
forloop. counter: By using this, the iteration of the loop starts from index 1. forloop. counter0: By using this, the iteration of the loop starts from index 0.
The key point is that you can't do this kind of thing in the Django template language.
Q11:-What does {{ forloop. counter }} prints? It will not print if for loop variable is not defined. It will count the number of times loop ran.
You would use forloop.last
. For example:
<ul> {% for item in menu_items %} <li{% if forloop.last %} class='last'{% endif %}>{{ item }}</li> {% endfor %} </ul>
{{ forloop.last }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With