从JSON到HTML表的迭代通过两个列表|瓶
问题描述:
输出,看人品如何开始在底部的另一个列表时结束:从JSON到HTML表的迭代通过两个列表|瓶
<table class="table">
<tr>
<th>Cast</th>
<th>Character</th>
</tr>
{% for cast in data[currentMovie]["cast"] %}
<tr>
<td>{{ cast }}</td>
{% endfor %}
{% for char in data[currentMovie]["character"] %}
<td>{{ char }}</td>
</tr>
{% endfor %}
</table>
我想知道的是如何得到它,它并排,如现在角色从演员名单的最后开始。任何帮助表示赞赏!输出如上所示。
答
您正在循环首先“投射”,然后是“角色”。这是问题。 你应该循环两者同时进行类似
for cast, char in zip(data[currentMovie]["cast"], data[currentMovie]["character"])
这是关于它的正确方法,但神社不喜欢邮编,我发现这个https://stackoverflow.com/questions/46176785/how-do-i-iterate -zip-list-in-jinja2-for-for-loop-and-display-values-in-html-ta感谢您的帮助! :) –