听起来你想同时遍历两个列表,换句话说就是zip()列表。
如果是这种情况,最好在视图中进行操作并在上下文中传递:
headers = ["X", "Y", "Z", "XX", "YY"]data = zip(headers, myarray.all())return render(request, 'template.html', {'data': data})然后,在模板中:
{% for header, row in data %} <tr> <th>{{ header }}</th> <td>{{ row }}</td> </tr>{% endfor %}


