Python 烧瓶错误请求错误;由于多个POST请求而出现问题
上面是我的Python/Flask代码 问题是,当我点击UpdateDescriptionSubmit按钮(即html代码中处理的第二篇文章)时,我得到一个400错误Python 烧瓶错误请求错误;由于多个POST请求而出现问题,python,html,flask,jinja2,Python,Html,Flask,Jinja2,上面是我的Python/Flask代码 问题是,当我点击UpdateDescriptionSubmit按钮(即html代码中处理的第二篇文章)时,我得到一个400错误 @app.route("/gallery-manager", methods = ["GET", "POST"]) def gallery_manager(): if request.method == "POST": if(request.form["image-url"] and request.form["d
@app.route("/gallery-manager", methods = ["GET", "POST"])
def gallery_manager():
if request.method == "POST":
if(request.form["image-url"] and request.form["description"]) is not None:
model.add_new_image(request.form["image-url"], request.form["description"])
id, image, description, amount_of_images = model.get_gallery()
return render_template("gallery-manager.html", image = image, description = description, amount_of_images = amount_of_images, id = id)
if request.form['update-description'] is not None:
print("hello")
id, image, description, amount_of_images = model.get_gallery()
return render_template("gallery-manager.html", image = image, description = description, amount_of_images = amount_of_images, id = id)
我意识到,当其中一个POST字段为空且无法找到时,就会发生此错误。我知道这是因为当我点击第二个POST submit按钮时,它会运行第一个POST检查(request.form[“image url”]等),并发现它满足了运行该代码的要求,但无法运行,因为更新描述仍然为空。我如何避免这种情况
换句话说,我如何处理多个POST方法
谢谢,这是因为表单中缺少表单应发送请求的操作部分
Bad Request
The browser (or proxy) sent a request that this server could not understand.
我将其发送到html代码所在的原始页面,并收到相同的错误。我将其发送到另一个带有POST方法处理程序的页面,但仍然收到相同的错误。我的另一个POST请求没有任何操作,工作正常(位于其上方)。我回答了您的问题。不抱歉,仍然是相同的错误。无论如何,谢谢
Bad Request
The browser (or proxy) sent a request that this server could not understand.
<form action="/whereYouWantToSendRequest" method="post">
<input type="text" name="image-url" value = "new"/>
<input type="text" name="update-description" value = "update"/>
if request.form["image-url"] == "new":
somethinggg
elif request.form["update-description"] =="update":
sommmm