【问题标题】:flask request.files empty even though request.args is not烧瓶 request.files 为空,即使 request.args 不是
【发布时间】:2020-06-07 04:53:30
【问题描述】:

我正在尝试将文件从表单上传到烧瓶服务器。我的 HTML(我正在使用 React)如下:

    <form action="/" method="post">
      <input type="file" id="placesCSV" name="placesCSV"></input>
      <input type="submit" />
    </form>

但python中的代码如下:

    @app.route('/', methods = ['POST'])
    def findRoutes():
      if request.method == 'POST':
        print(request.args)
        print(request.files)

正确打印request.args 的文件名,但request.files 为空。我也得到:

错误请求

浏览器(或代理)发送了此服务器无法理解的请求。

我用 'GET' 而不是 'POST' 尝试了同样的方法,我得到了相同的结果。

【问题讨论】:

    标签: python flask file-upload python-requests


    【解决方案1】:

    我认为您应该将 request.method 更改为 POST

        def findRoutes():
          if request.method == 'POST':
            print(request.args)
            print(request.files)
    

    【讨论】:

    • 试过了,我得到了同样的结果。
    • @app.route('/', methods=['GET', 'POST'])
    • 表单方法应该是post而不是得到这个应该在表单jsx元素中修复
    • 我想这就是你的意思
      。刚试过这个。结果还是一样。
    猜你喜欢
    • 1970-01-01
    • 2018-10-11
    • 2014-06-13
    • 2018-12-30
    • 2020-11-15
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    相关资源
    最近更新 更多