【发布时间】:2019-10-16 01:35:04
【问题描述】:
我有一个列表字典。例如:
result = {
'a': ['x', 'y', 'z'],
'b': ['p', 'q', 'r'],
'c': ['m', 'n', 'o']
}
我希望 a、b 和 c 成为我的表格的标题以及该特定列下的相应列表。
我已经像这样从cherrypy将字典传递给html return tmpl.render(result = result)
补充: 这是写的html代码
<table id="myTable"> {% for k,v in result.items() %}
<th> {{ k }}</th>
{% for val in v %}
<tr>
<td> {{ val }}</td>
</tr>
{% endfor %} {% endfor %}
</table>
【问题讨论】:
-
你到底面临什么问题?
-
@StephanSchrijver 输出格式不理想。标题将位于左侧,并且列表中该特定标题的所有值都显示在一行中。我想要一个 html 表格中的字典,顶部有标题,标题下有相应的列表元素。
标签: html python-3.x dictionary flask cherrypy