通过两个列表从JSON迭代到HTML表|烧瓶

问题描述 投票:0回答:1

输出,看看当另一个列表结束时角色从底部开始:

<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>

我想知道的是如何将它并排放置,因为现在角色从演员表的末尾开始。任何帮助表示赞赏!输出如上所示。

python html json list html-table
1个回答
0
投票

你首先循环“cast”然后循环“character”。这就是问题所在。你应该同时循环两个

for cast, char in zip(data[currentMovie]["cast"], data[currentMovie]["character"])
© www.soinside.com 2019 - 2024. All rights reserved.