Get an uploaded file from a WTForms field

request.files is a dictionary where the keys are the names of the file fields. You can get the name of a WTForms field with my_form.my_field.name. So you can access the data uploaded from that field with request.files[my_form.my_field.name]. Rather than using the WTForms FileField, you can use the Flask-WTF FileField instead. It provides a data attribute … Read more

Flask WTForms: Difference between DataRequired and InputRequired

Short Answer Unless you have a good reason you should use InputRequired Why? Lets look at some notes from the docs/code for DataRequired() : Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired looks at the post-coercion data. and NOTE this validator used to … Read more

Multiple forms in a single page using flask and WTForms

The solution above have a validation bug, when one form cause a validation error, both forms display an error message. I change the order of if to solve this problem. First, define your multiple SubmitField with different names, like this: class Form1(Form): name = StringField(‘name’) submit1 = SubmitField(‘submit’) class Form2(Form): name = StringField(‘name’) submit2 = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)