如何返回模板瓶

时间:2016-11-30 18:05:12

标签: python flask jinja2

如何在烧瓶模板上输出列表的列表[]?

我有桌子[]

table = [[ str(i + 1)  if (i + 1) % 2 == 0 else i + 1,
                   href[i] if (i + 1) % 2 == 0 else href[i],
                   href2[i] if (i + 1) % 2 == 0 else href2[i]] for i in range(len(href))]

return render_template('index.html',table=table)

我想要这样

<table>
<tr>
{% for table in table %}
<th>{{href[1]}} ,{{href2[1]}}</th>
{% endfor %}
</tr>
</table>

我想要这个输出

<table>
<tr>
<th>href[1] ,href2[1]</th>
<th>href[2] ,href2[2]</th>
<th>href[3] ,href2[3]</th>
...
</tr>
</table>

1 个答案:

答案 0 :(得分:0)

所以看起来你的桌子是

[ [ "A", "B", "C" ],   
  [ "1", "2", "3" ] ]

所以你的循环应该是

{% for row in table %}
   <th>{{row[0]}} ,{{row[1]}}</th>
{% endfor %}