【问题标题】:Flask giving error 400 on file uploadFlask 在文件上传时出现错误 400
【发布时间】:2015-03-17 17:51:30
【问题描述】:

我有以下

<form action="classify_upload" method="post" id="upload-form">
    <input type="file" name="imagefile" id="imagefile"/>
    <input type="submit" />
</form>

在我的烧瓶 webapp 中,我有以下规则:

@webapp.route('/upload', methods=['POST'])
def upload():
    try:
        imagefile = flask.request.files['imagefile']
        ...
    except Exception as err:
        ...

但是我得到了一个error 400: bad request,从我的谷歌搜索中告诉我Flask 找不到键'imagefile' 下的文件,这是html 中输入的名称。任何想法为什么它没有找到它?

【问题讨论】:

    标签: python upload flask


    【解决方案1】:

    原来我需要在表单中包含enctype,所以 html 应该是

    <form action="classify_upload" method="post" id="upload-form"  enctype="multipart/form-data">
        <input type="file" name="imagefile" id="imagefile"/>
        <input type="submit" />
    </form>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-29
      • 2014-01-31
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      • 1970-01-01
      • 2012-12-21
      • 2016-08-02
      相关资源
      最近更新 更多