【发布时间】:2015-10-16 06:21:09
【问题描述】:
我有一个上下文变量:
"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 正在根据当前迭代更改其值。我怎样才能做到这一点?
【问题讨论】:
标签: python django django-templates jinja2