【发布时间】:2021-05-08 00:54:08
【问题描述】:
我在 html 中添加一个表格,显示 sqlite fetchall 的结果并使用烧瓶提供 html,但我需要一种方法让用户在前端和数据库中删除特定的记录行.有没有办法做到这一点?提前感谢您的帮助!
我的 HTML 表格:
<table style="text-align: center; width: 100%;">
<thead>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Update</td>
<td>Delete</td>
</thead>
{% for row in rows %}
<tr>
<td>{{row["row1"]}}</td>
<td> {{row["row2"]}}</td>
<td>{{row["row3"]}}</td>
<td><button type="button" id="remove">Update Row</button></td>
<td><button type="button" id="remove">Delete Row</button></td>
</tr>
{% endfor %}
</table>
我的 Python 代码:
@app.route('/database', methods=['GET', 'POST'])
def database():
connection = sqlite3.connect(r'')
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
datasearch = "select * from Items where ID= " + str(session['ID'])
print(datasearch)
cursor.execute(datasearch)
rows = cursor.fetchall()
return render_template("database.html", rows = rows)
【问题讨论】: