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

时间:2017-12-27 11:12:35

标签: python html json list html-table

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

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

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

1 个答案:

答案 0 :(得分:0)

你先循环播放&#34;演员&#34;然后&#34;字符&#34;。这就是问题所在。 你应该像

一样同时循环
for cast, char in zip(data[currentMovie]["cast"], data[currentMovie]["character"])