这是一个用于Python添加和删除任务的网络应用程序。
这是add_tasks函数:
@app.route("/add", methods=["GET", "POST"])
@login_required
def add():
if request.method == "POST":
add = request.form.get("add")
quantity = request.form.get("quantity")
if not add:
return apology("Please add an item")
db.execute("INSERT INTO history (add, quantity, user_id) VALUES (:add, :quantity, :user_id);", add=add, quantity=quantity, user_id=session["user_id"])
return redirect("/")
else:
return render_template("add.html")
然后我的删除功能仅将存储的项目从SQL数据库中取出SELECT,以便删除它们。
@app.route("/delete", methods=["GET", "POST"])
@login_required
def delete():
if request.method == "POST":
db.execute("DELETE FROM history (add, quantity, user_id) VALUES (:add, :quantity, :user_id);", add=add, quantity=0, user_id=session["user_id"])
else:
rows = db.execute("SELECT add FROM history WHERE user_id=:user_id GROUP BY add",
user_id=session["user_id"])
return render_template("delete.html", add=[row["add"] for row in rows])
此删除功能会导致内部服务器错误。这有什么问题吗?
白衣染霜花
相关分类