form.validate_on_submit()和form.validate()之间的区别 [英] Difference between `form.validate_on_submit()` and `form.validate()`

查看:866
本文介绍了form.validate_on_submit()和form.validate()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

form.validate_on_submit()form.validate()有什么区别?

Flask WTF文档中,作者使用了form.validate_on_submit() .该代码有效.当我用form.validate()替换form.validate_on_submit()时,我发现行为没有区别.我在源代码中找不到form.validate_on_submit(),但是我设法找到form.validate() 代码.

In the Flask WTF docs, the author uses form.validate_on_submit(). The code works. When I substitute form.validate_on_submit() with form.validate(), I see no difference in behavior. I couldn't find form.validate_on_submit() in the source, but I managed to find form.validate() code.

推荐答案

validate_on_submit()is_submitted() and validate()的快捷方式.

来自源代码,行89,如果提交的表单是活动请求,并且方法是POST,PUT,PATCH或DELETE,则is_submitted()返回True.

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.

通常来说,它用于路由可以接受GET和POST方法并且您只想对POST请求进行验证的情况.

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.

这篇关于form.validate_on_submit()和form.validate()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆