@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))
上面是我用来保存文件的代码。但是在尝试保存文件时会弹出以下错误
flask.debughelpers.DebugFilesKeyError
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.
浏览器改为传输一些文件名。
有人可以帮我弄这个吗
最佳答案
在您的 html 表单标签中包含
<form action="/path" method="post" enctype="multipart/form-data">
</form>
关于file-upload - flask 中的文件上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47679398/