For Loop Template

linkaiyi
Follow

For Loop

Django provides it. You can use either:

{{ forloop.counter }} index starts at 1.
{{ forloop.counter0 }} index starts at 0.

In template, you can do:

{% for item in item_list %}
    {{ forloop.counter }} # starting index 1
    {{ forloop.counter0 }} # starting index 0

    # do your stuff
{% endfor %}

Also one can use this:

{% if forloop.first %}

or

{% if forloop.last %}
Object has 0 attachments

Was this article helpful?

This article is viewed 19 times!

Recent Viewed Articles

0 Comments

Leave a Comment

Support