确定为什么WTForms表单未通过验证 [英] Determine why WTForms form didn't validate
问题描述
我叫form.validate_on_submit()
,但它返回了False
.我如何找出表单未通过验证的原因?
I called form.validate_on_submit()
, but it returned False
. How can I find out why the form didn't validate?
推荐答案
对于整个表单,form.errors
包含一个字段映射到错误列表.如果不为空,则表单未通过验证.对于单个字段,field.errors
包含该字段的错误列表.该列表与form.errors
中的列表相同.
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()
执行验证并填充errors
.使用Flask-WTF时,form.validate_on_submit()
会执行另一项检查,以确认request.method
是提交"方法,这主要意味着它不是GET
请求.
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.
这篇关于确定为什么WTForms表单未通过验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!