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

后端 未结 1 790
难免孤独
难免孤独 2021-01-02 02:33

What is the difference between form.validate_on_submit() and form.validate()?

In the Flask WTF docs, the author uses form.validate_on

相关标签:
1条回答
  • 2021-01-02 02:41

    validate_on_submit() is a shortcut for is_submitted() and validate().

    From the source code, line 89, is_submitted() returns True if the form submitted 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 want to validate only on a POST request.

    0 讨论(0)
提交回复
热议问题