Current iteration from the end of a for loop in a Django template - forloop.revcounter


Django tip:

You can use revcounter to get the number of iterations from the end of a for loop in your Django templates like so:

{% for item in item_list %}
    {{ forloop.revcounter }}  # starting index 1
    {{ forloop.revcounter0 }} # starting index 0
{% endfor %}