[英]Flask returns 405 Method Not Allowed even though POST is specified
上傳到我的upload_file
路由時,我收到 405 Method Not Allowed 錯誤。 我已經指定路由接受 GET 和 POST 方法,所以我不確定為什么它不起作用。
@app.route('/upload', methods=["GET, POST"])
def upload_file():
if request.method == 'GET':
return render_template("home.html")
elif request.method == 'POST':
if 'file' not in request.file:
return render_template("home.html")
file = request.files['file']
if file.filename == '':
return render_template("home.html")
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
converted_file = convert(file)
return render_template("home.html", converted_file=converted_file, img_src=UPLOAD_FOLDER+filename)
<form method="post" enctype="multipart/form-data" action="/upload" >
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
@app.route('/upload', methods=["GET, POST"])
應該:
@app.route('/upload', methods=["GET", "POST"])
您給出了一個帶有一個字符串“GET, POST”的列表,而不是一個帶有兩個字符串的列表:“GET”和“POST”。
PS:如此處所述: 請勿在生產中使用 run()。
不要在生產環境中使用 run()。 它不是為了滿足生產服務器的安全和性能要求。 相反,請參閱部署選項以獲取 WSGI 服務器建議。
請閱讀部署選項
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.