'Set Flask-WTForms FileField data when you instantiate the form
I have a form with a FileField, and it works fine when I submit the form.
However, I would like the user to be able to edit their response to the form, so I need to be able to prepopulate it when they load the page. I am able to do this with the other fields by setting their data attributes, when I do similar for the FileField, it is reset to nothing when the form is submitted:
e.g.
#WTForms class
class UserForm(FlaskForm):
username = StringField('User name', validators=[DataRequired(), length(1, 50)])
profile_pic = FileField('Profile Picture', validators=[Optional()])
#In main app user is a dictionary holding data from a mongodb query
user_form.username.data = user['username']
user_from.profile_pic.data = user['profile_pic']
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
