[Answer]-Django loop variable as key

1👍

the thing you’re probably looking for is a magic variable {{ forloop.counter }} (or {{ forloop.counter0 }} if you want to use zero-based index) available inside {% for %} loop:

{% for file in files %}
   <img title="{{ forloop.counter }}" src="{{file.data_files.url}}"/>
{% endfor %}

Leave a comment