因此,我将json对象通过render_template(烧瓶)传递到我的.html页面中,并使用jinja和以下代码,我想在表中创建表行:
{% if showData %}
<table class="table table-striped">
<thead class="thead-light">
<tr>
<th scope="col">#</th>
<th scope="col">Performer Name</th>
<th scope="col">Twitter Handle</th>
</tr>
</thead>
<tbody>{{showData}}
{% for performer in showData.performers %}
<tr>
<th scope="row">1</th>
<td>{{performer}}</td>
<td>@mdo</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
如果我打印出对象“ showData”(如用{{showData}}在代码中看到的那样),它将打印出整个json,如下所示:
[{u'category': u'Comedy', u'rating': 5, u'name': u'first show', u'img': u'firstshow.jpg', u'performers': [u'Bob bob', u'Alex alex', u'James james'], u'url': u'first_show', u'venue': 2, u'viewTimes': [u'12:00', u'14:00', u'16:00'], u'description': u'blah blah blah'}]
但是,如果我尝试遍历showData.performers,它不会显示任何内容。即使我尝试打印showData.name,它也是空的
任何想法为何?干杯