Difference between `form.validate_on_submit ()` and `form.validate ()`

What is the difference between form.validate_on_submit()

and form.validate()

?

In the Flask WTF docs, the author uses form.validate_on_submit()

. The code works. When I replace form.validate_on_submit()

with form.validate()

, I see no difference in behavior. I couldn't find it form.validate_on_submit()

in the source, but I did manage to find the form.validate()

code .

+7


source to share


1 answer


validate_on_submit()

is a shortcut for is_submitted() and validate()

.

From the source , line 89, is_submitted()

returns True if the submitted form is an active request and the method is POST, PUT, PATCH, or DELETE.



Generally speaking, it is used when a route can accept both GET and POST methods and you only want to validate on a POST request.

+10


source







All Articles