mbr / flask-bootstrap

Ready-to-use Twitter-bootstrap for use in Flask.
http://pypi.python.org/pypi/Flask-Bootstrap
Other
1.58k stars 724 forks source link

quick_form does not set enctype when FileField present #177

Open pn2 opened 6 years ago

pn2 commented 6 years ago

I read in the docs:

enctype attribute. If None, will automatically be set to multipart/form-data if a FileField is present in the form.

However, in an application I work on, this seems not to be the case. I had to set enctype explicitly in the template (it does not work without the enctype below):

<div class="col-md-4">
   {{ wtf.quick_form(form, enctype="multipart/form-data") }}
</div>

The form declaration is as follows:

class xyzForm(FlaskForm): 
    photo = FileField('Image file', validators=[FileRequired(), FileAllowed(['jpg', 'png'], 'Images only!')])
    submit = SubmitField('Submit')

and it is instantiated with

form = xyzForm()
# also tried: form = xyzForm(CombinedMultiDict((request.files, request.form)))
$ pip3 show flask_bootstrap
Name: Flask-Bootstrap
Version: 3.3.7.1
$ pip3 show flask_wtf
Name: Flask-WTF
Version: 0.14.2
bianyunzhi95 commented 6 years ago

I also have got the same problem.