【发布时间】:2022-01-03 13:50:19
【问题描述】:
如何通过以下方式遍历 django 模板中的项目
{% for brand in categories%}
<div class="brand-col">
<figure class="brand-wrapper">
<img src="{{brand.product_feature_image.image.url}}" alt="Brand" width="410" height="186" /> (item1)
</figure>
<img src="{{brand.product_feature_image.image.url}}" alt="Brand" width="410" height="186" /> (item2)
</figure>
</div>
{% endfor %}
<div class="brand-col">
<figure class="brand-wrapper">
<img src="{{brand.product_feature_image.image.url}}" alt="Brand" width="410" height="186" /> (item3)
</figure>
<img src="{{brand.product_feature_image.image.url}}" alt="Brand" width="410" height="186" /> (item4)
</figure>
</div>
<div class="brand-col">
<figure class="brand-wrapper">
<img src="{{brand.product_feature_image.image.url}}" alt="Brand" width="410" height="186" /> (item5)
</figure>
<img src="{{brand.product_feature_image.image.url}}" alt="Brand" width="410" height="186" /> (item6)
</figure>
</div>
参考:(括号内的项目编号仅供参考) 在这里,首先我想在 figure 标记上循环 1 和循环 2,然后我想在图上的 div 内循环整个 div 和循环 3 和循环 4标记。
我尝试使用循环,但没有运气。任何帮助将不胜感激。
【问题讨论】:
-
不幸的是,这个问题不够清晰。什么是第 1 项和第 2 项等?
-
您好 Yusuf,感谢您的评论。实际上我试图将循环计数表示为 item1,依此类推
标签: django django-templates django-template-filters