首页 > 解决方案 > 使用 Django 模板标签中的索引访问多个列表的值

问题描述

所以我有三个相同长度的列表ab以及c另一个d只是从 0 到 的数字的列表len(a)。我想在 html 表中显示前三个列表。所以我写道:

{% for i in d %}

<tr>
    <td>{{a.i}}</td>
    <td>{{b.i}}</td>
    <td>{{c.i}}</td>
</tr>

{% endfor %}

出于某种原因,这不起作用,但如果更改i为任何数字(如 0),它会正确显示每一行中每个列表的第一项。如何在模板标签中使用索引来显示我想要的内容?

标签: htmldjangopython-3.xdjango-templates

解决方案


推荐阅读