Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine why WTForms form didn't validate

I called form.validate_on_submit(), but it returned False. How can I find out why the form didn't validate?

like image 544
Andrea Tulimiero Avatar asked Sep 08 '25 09:09

Andrea Tulimiero


1 Answers

For the whole form, form.errors contains a map of fields to lists of errors. If it is not empty, then the form did not validate. For an individual field, field.errors contains a list of errors for that field. The list is the same as the one in form.errors.

form.validate() performs validation and populates errors. When using Flask-WTF, form.validate_on_submit() performs an additional check that request.method is a "submit" method, which mostly means it is not a GET request.

like image 149
davidism Avatar answered Sep 10 '25 05:09

davidism