首页 > 解决方案 > 如何删除数据库中的项目而不会遇到 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)

标签: pythonsql

解决方案


您需要删除一行的语法如下;

DELETE FROM table_name WHERE condition;

因此,请尝试将您的更改db.execute为以下内容;

"DELETE FROM staff WHERE id=1"

请参阅本指南了解更多信息


推荐阅读