I have a form with flask-wtf for uploading images, also file field can be multiple fields.
my form:
class ComposeForm(Form):attachment = FieldList(FileField(_('file')), _('attachment'))add_upload = SubmitField(_('Add upload'))
my view:
if form.validate_on_submit():if form.add_upload.data:form.attachment.append_entry()return render_template('mailbox/compose.html', form=form)else:form.attachment.append_entry()
my template:
<form method="POST" enctype="multipart/form-data" action=".">{% for field in form %}{{field}}{% endfor %}
</div>
When I use enctype="multipart/form-data"
in the form, append_entry
doesn't work. It only appends one more field.
Again I click on add_upload
, but after refresh I have again only one field (not two).
How can I fix this? There is no error, I think, because enctype wtform forgets how many fields I have to add more.