首页 > 解决方案 > 如何在 Jinja 2 html 表中显示 Python Flask DB 整体

问题描述

我目前有一个数据库,我想通过特定路线在我的网络应用程序中查看其表。

我想通过应用程序在一个易于阅读的表格中查看数据库中整体的 Jinga2 输出。

我目前拥有的作品,但它在一行中显示所有条目,而不是像 Excel 电子表格那样的表格格式。

我的代码如下:

 {% for row in rows %}  <tr>
  <td>{{ row.id }}</a></td>
  <td>{{ row.question }}</td>
  <td bgcolor="{{ row.stat_colour }}">{{ row.unit_status }}</td>  </tr>  >     
 {% endfor %}

标签: pythonhtmlflask

解决方案


对于任何有类似问题的人,我可以通过为我的 html 使用下面的代码块来让它工作:

 <html !DOCTYPE>
 <head>
 <title>SQLite 3 DB Questions Table</title>
 </head>
 <body>
 <table>
 {% for row in rows %}
 <tr>
     <td>{{ row.id }}</td>
     <td>{{ row.question }}</td>
 </tr>
 {% endfor %}
 </table>
 </body>
 </html>

推荐阅读