python - 如何删除数据库中的项目而不会遇到 405 错误
问题描述
如何避免 DELETE 方法给我一个 405 错误?有没有办法从我的数据库中删除行?
我尝试在我的根目录的 web.config 文件中包含以下内容,但这不起作用。
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
我在下面包含了代码片段以供参考。
HTML:
<form method = "post" class= "my-5 text-center">
<caption>Remove Staff</caption>
<select name="staff" style="width: 300px">
<option></option>
{% for p in people %}
<option name="staff">{{ p.name }}</option>
{% endfor %}
</select>
<input type= "submit"/>
</form>
Python:
@app.route("/deletestaff")
def deletestaff():
if request.method == "POST":
name = request.form.get("name")
db.execute("DELETE * FROM staff WHERE id=1")
people = db.execute("SELECT name, id FROM staff")
return render_template("deletestaff.html", people=people)
else:
people = db.execute("SELECT name, id FROM staff")
return render_template("deletestaff.html", people=people)
解决方案
您需要删除一行的语法如下;
DELETE FROM table_name WHERE condition;
因此,请尝试将您的更改db.execute
为以下内容;
"DELETE FROM staff WHERE id=1"
推荐阅读
- typescript - 如何在 TypeScript 中克隆类实例?
- android - IllegalStateException:已添加片段:FragmentPagerAdapter
- php - 如何在树枝中打印变量
- python - 我怎样才能总结一个列表的数量
- python-3.x - Python3如何更改错误栏样式
- javascript - 提交后如何在jQuery mobile的子菜单中保持关闭按钮的样式
- angular - 防护后组件不渲染,角度 9
- ruby-on-rails - 如何在 ActiveRecord 中检查数据值以进行验证?
- python - 将列表与字典进行比较并生成新列表。新列表的长度为 1?
- javascript - 从 Chrome 扩展下载完整的网页