【发布时间】:2021-12-17 10:44:15
【问题描述】:
我有一个表,它是 Sqlite3 搜索的结果,它显示在视图 disp.html 中。它显示数据库中每条记录的记录 ID 和元数据。当我从表中选择记录 ID 时,它应该显示所选记录 ID 的详细数据。但是发生的情况是,无论选择什么记录 ID,我总是将第一个 ID 返回到路由。
如何让视图将所选 ID 返回到路由?
disp.html
{% extends "layout.html" %}
{% block maindisplay %}
<form action="/display" method="post">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>Data ID</th>
<th>Data One</th>
<th>Data Two</th>
<th>Data Three</th>
<th>Data Four</th>
<th>Data Five</th>
</tr>
</thead>
<tbody>
{% for data in display_data %}
<tr>
<td><input type="hidden" name="pid" value='{{ data["ID"] }}'><button btn class="formatButton">{{ data["IDo"] }}</button></td>
<td>{{ data["one"] }}</td>
<td>{{ data["two"] }}</td>
<td>{{ data["three"] }}</td>
<td>{{ data["four"] }}</td>
<td>{{ data["five"] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
{% endblock %}
视图的输出
ID Data One Data Two Data Three Data Four Data Five
1 One1 Two1 Three1 Four1 Five1
2 One2 Two2 Three2 Four2 Five2
3 One3 Two3 Three3 Four3 Five3
路线
@app.route("/display", methods=["GET", "POST"])
def list_data():
if request.method == "POST":
dataZero=request.form.get("pid")
...
return render_template("pdisplay.html", dataZero=dataZero)
【问题讨论】:
标签: python sqlite flask jinja2