[英]Flask Error: “Method Not Allowed The method is not allowed for the requested URL”
I am trying to upload an Excel file in my Flask app and I am getting the following error:我正在尝试在我的 Flask 应用程序中上传 Excel 文件,但出现以下错误:
Method Not Allowed: The method is not allowed for the requested URL.
方法不允许:请求的 URL 不允许该方法。
I am not entirely sure why I am getting this error.我不完全确定为什么会收到此错误。
Here is my Flask code:这是我的 Flask 代码:
@app.route("/upload", methods = ['GET', 'POST'])
def upload():
#user_file is the name value in input element
if request.method == 'POST' and 'user_file' in request.files:
filename = docs.save(request.files['user_file'])
return filename
return render_template('upload.html')
Here is my upload html code:这是我上传的 html 代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>upload</title>
</head>
<body>
<form method="POST" enctype=multipart/form-data action ="{{url_for('upload')}}">
<input type="file" name="user_file">
<input type="submit">
</form>
</body>
</html>
As a wild guess you are running Flask not in debug mode.作为一个疯狂的猜测,您正在运行 Flask 而不是在调试模式下。 When you changed your files, the changes are not being reflected.
当您更改文件时,更改不会被反映。 Also i don't know if you are using flask-uploads, but i suggest using Flask-reuploaded , the maintained version of flask-uploads.
另外我不知道您是否使用烧瓶上传,但我建议使用Flask-reuploaded ,烧瓶上传的维护版本。 No change to code needed, just different package.
无需更改代码,只需不同的 package。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.