后端发送的是列表套字典的格式
queryset = [{'id': 1, 'insect_name': '稻纵卷叶螟', 'crop': '水稻', 'harm_days': 7}, {'id': 2, 'insect_name': '棉蚜', 'crop': '棉花', 'harm_days': 5}]
传递到前端使用django模板语句进行遍历,渲染到table中
<div style="margin-top:10px;">
<table>
<thead>
{% for i in queryset.0.keys %}
<tr>
<th>{{ i }}</th>
</tr>
{% endfor %}
</thead>
{% for item in queryset %}
{% for i in item.values %}
<tbody>
<tr>
<td>{{ i }}</td>
</tr>
</tbody>
{% endfor %}
{% endfor %}
</table>
</div>
结果他是竖着展示的了,字段数值都在一列,我想让他像正常表格一样展示出来该怎么改一下呢,谢谢了!!