烧瓶中的文件上传错误 [英] File upload error in flask

查看:117
本文介绍了烧瓶中的文件上传错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@app.route('/registerdriver', methods=['POST'])
def register_driver():
    fname = request.form['fname']
    lname = request.form['lname']
    email = request.form['email']
    mobno = request.form['mobno']
    password = request.form['password']

    file = request.files['driving_license']
    file.filename = mobno+"_"+fname

    filename = secure_filename(file.filename)
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

以上是我用于保存文件的代码.但是在尝试保存文件时弹出以下错误

Above is the code I used for saving the file. However the following error pops out while trying to save the file

flask.debughelpers.DebugFilesKeyError

flask.debughelpers.DebugFilesKeyError

flask.debughelpers.DebugFilesKeyError:您尝试访问文件request.files词典中的"driving_license",但没有存在.该请求的模仿类型是应用程序/x-www-form-urlencoded",而不是"multipart/form-data"这意味着没有文件内容被传输.解决此错误您应该在表单中提供enctype ="multipart/form-data".

flask.debughelpers.DebugFilesKeyError: You tried to access the file "driving_license" in the request.files dictionary but it does not exist. The mimetype for the request is "application/x-www-form-urlencoded" instead of "multipart/form-data" which means that no file contents were transmitted. To fix this error you should provide enctype="multipart/form-data" in your form.

浏览器改为传输了一些文件名.

The browser instead transmitted some file names.

有人可以帮我吗

推荐答案

在您的html表单标记中

In your html form tag include

<form action="/path" method="post" enctype="multipart/form-data">
</form>

这篇关于烧瓶中的文件上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆