Flask file not detecting on upload

五迷三道 提交于 2019-12-01 11:36:42

request.form only contains form input data. request.files contains file upload data. You need to pass the combination of both to the form. Since your form inherits from Flask-WTF's Form (now called FlaskForm), it will handle this automatically if you don't pass anything to the form.

form = BrandForm()

if form.validate_on_submit():
    ...

Without Flask-WTF, use a CombinedMultiDict to combine the data and pass that to the form.

from werkzeug.datastructures import CombinedMultiDict

form = BrandForm(CombinedMultiDict((request.files, request.form)))

if request.method == 'POST' and form.validate():
    ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!