【发布时间】:2021-05-15 00:02:56
【问题描述】:
我想将我的查询从 SQLite3 显示到引导表中。但它似乎不起作用并且不会显示表格。 附上我的代码
views.py
@main.route('/currentlist', methods=["GET"])
def current():
if request.method == 'GET':
Connection = sqlite3.connect('C:\\Backup_old\\Task\\e_ticket\\my_app\\db\\customer.db')
cursor = Connection.cursor()
query2 = "SELECT * from customer"
cursor.execute(query2)
test = cursor.fetchall()
return render_template('overview.html', testform = test)
HTML
<div class= "content">
<table id="dtBasicExample" class="table" width="100%">
<thead>
<tr>
<th class="th-sm">Date
</th>
<th class="th-sm">time
<th class="th-sm">customer
</th>
<th class="th-sm">pic
</th>
<th class="th-sm">category
</th>
<th class="th-sm">description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>9 December 2021</td>
<td>15:30:00</td>
<td>AB Corp.</td>
<td>Bob</td>
<td>network</td>
<td>network is down</td>
</tr>
<tr>
<td>9 December 2021</td>
<td>17:30:00</td>
<td>AB Corp.</td>
<td>Alex</td>
<td>computer</td>
<td>computer is broken</td>
</tr>
<tr>
<td>10 December 2021</td>
<td>05:32:00</td>
<td>CD Corp.</td>
<td>Bob</td>
<td>Server</td>
<td>server is down</td>
</tr>
<tr>
<td>12 December 2021</td>
<td>10:30:00</td>
<td>AB Corp.</td>
<td>Bob</td>
<td>printer</td>
<td>printer is down</td>
</tr>
</tbody>
</table>
</div>
应该是这样,但数据来自数据库 enter image description here
我读过很多类似的问题,但大多数都使用 SQLAlchemy。
非常感谢您的帮助!
【问题讨论】:
标签: python html sqlite flask bootstrap-table