确定为什么WTForms表单未通过验证 [英] Determine why WTForms form didn't validate

查看:150
本文介绍了确定为什么WTForms表单未通过验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我叫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屋!

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