这是一个用于Python添加和删除任务的网络应用程序。这是add_tasks函数:@app.route("/add", methods=["GET", "POST"])@login_requireddef 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_requireddef 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])此删除功能会导致内部服务器错误。这有什么问题吗?
1 回答
白衣染霜花
TA贡献1796条经验 获得超10个赞
最后,POST
我的部分DELETE
功能是错误的。我已经设法找到这个解决方案:
db.execute("DELETE FROM history WHERE user_id=:user_id and add=:add;", user_id=session["user_id"], add=add)
添加回答
举报
0/150
提交
取消