我正在尝试创建一个索引文件,其中显示两个表:
1.用户帐户详细信息(已完成)
1.用户借用的设备。
在第二个表中,我尝试添加一个按钮,允许用户归还借用的设备(通过更新SQL文件中的数据文件)。
Python(app.py文件):
@app.route("/", methods=["GET", "POST"])
@login_required
def index():
#Table 1 (Done)
rows1 = db.execute("SELECT name AS n FROM users WHERE id = ?", session["user_id"])
row1 = rows1[0]
name = (row1["n"])
rows2 = db.execute("SELECT user_id AS i FROM users WHERE id = ?", session["user_id"])
row2 = rows2[0]
user_id = (row2["i"])
rows3 = db.execute("SELECT phone AS p FROM users WHERE id = ?", session["user_id"])
row3 = rows3[0]
phone = (row3["p"])
#Table 2
borrowed = db.execute("SELECT equipments.eqp_name, timestamp, purpose, transactions.details, transactions.eqp_serial, return_date FROM transactions JOIN equipments ON equipments.eqp_serial = transactions.eqp_serial WHERE user_id = ? AND availability = 2", session["user_id"])
** if request.method == "POST":
# TODO**
else:
return render_template("index.html", name = name, user_id = user_id, phone = phone, borrowed = borrowed)
HTML(index.html文件)
</table>
<br>
<table>
<tr style="background-color: #D6DBDF">
<th>Items borrowed</th>
<th>Serial</th>
<th>Borrow Date</th>
<th>Expected Return Date</th>
<th>Purpose</th>
<th>Details</th>
<th>Return</th>
</tr>
<!--equipment borrowed under user for loop-->
{% for borrow in borrowed %}
<tr>
<td>{{ borrow.eqp_name }}</td>
<td>{{ borrow.eqp_serial }}</td>
<td>{{ borrow.timestamp }}</td>
<td>{{ borrow.return_date }}</td>
<td>{{ borrow.purpose }}</td>
<td>{{ borrow.details }}</td>
<form method = "post">
<td><button name="return">Return</button></td>
</form>
</tr>
{% endfor %}
</table>
我希望它看起来像like this。点击返回栏按钮后,该设备的SQL数据将更新为可用,允许其他用户以后借用。
我该怎么做?
1条答案
按热度按时间mwg9r5ms1#
**是的,**可以在第二个表中添加一个按钮,允许用户通过更新SQL文件中的数据文件来归还借用的设备。
在index.html中
现在更新app.py
现在,当用户单击“Return”按钮时,将向/return_equipment端点发送带有设备序列号的POST请求。然后,服务器将更新数据库中设备的可用性。