遍历 Django 模板中的一个列表

iterate over a len of list in Django Template

我有一个上下文变量:

"images": [
        {
            "date": "2015-06-02T11:51:53Z",
            "image": "auction/Screenshot_from_2015-05-18_235741.png",
            "auction_id": 1,
            "id": 1
        },
        {
            "date": "2015-06-23T09:38:45Z",
            "image": "auction/Screenshot_from_2015-06-22_203407.png",
            "auction_id": 1,
            "id": 2
        },
        .....
    ],

我想按以下方式遍历这个字典列表

{% for image in images %}
    <a class="thumb-item-link" data-slide-index="{{over here should be the index of the current iteration}}" href=""><img src="/media/{{image.image}}" alt="img"/></a> 
{% endfor %}

例如:-

<a class="thumb-item-link" data-slide-index="0" href=""><img src="/media/auction/Screenshot_from_2015-05-18_235741.png" alt="img"/></a> 

<a class="thumb-item-link" data-slide-index="1" href=""><img src="/media/auction/Screenshot_from_2015-06-22_203407.png" alt="img"/></a> 

<a class="thumb-item-link" data-slide-index="2" href=""><img src="/media/auction/Screenshot_from_2015-06-22_203488.png" alt="img"/></a> 

这里 data-slide-index 正在根据当前迭代更改其值。我怎样才能做到这一点?

你可以使用这个 link:

{{forloop.counter0}}

并且每个循环中的django将从0开始枚举索引。