简体   繁体   English

Flask 错误:“方法不允许 请求的 URL 不允许该方法”

[英]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.

相关问题 Flask 错误:“方法不允许 请求的 URL 不允许该方法” - Flask Error: "Method Not Allowed The method is not allowed for the requested URL" Flask 错误:方法不允许 请求的 URL 不允许该方法 - Flask error: Method Not Allowed The method is not allowed for the requested URL Flask 错误:方法不允许 请求的 URL 不允许该方法 - Flask error : Method Not Allowed The method is not allowed for the requested URL Python Flask:错误“请求的 URL 不允许使用该方法” - Python Flask: Error "The method is not allowed for the requested URL" 不允许的方法 请求的 URL 不允许使用该方法。 在 DELETE 方法烧瓶上 - Method Not Allowed The method is not allowed for the requested URL. on DELETE Method Flask Python、Flask:方法不允许,请求的方法不允许 URL - Python, Flask: Method Not Allowed, The method is not allowed for the requested URL Python flask flask不允许的方法所请求的URL不允许使用该方法 - Python flask Method Not Allowed The method is not allowed for the requested URL Flask - POST - 请求的URL不允许使用该方法 - Flask - POST - The method is not allowed for the requested URL 所请求的URL不允许使用该方法。 在烧瓶 - The method is not allowed for the requested URL. in Flask 如何修复 Flask 中的“请求的 URL 不允许使用该方法” - How to fix "The method is not allowed for the requested URL" in Flask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM