如何查看WTForms验证错误? [英] how to view WTForms validation errors?

查看:75
本文介绍了如何查看WTForms验证错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些基本测试,但测试失败.

I am writing some basic tests and have a test failing.

def test_new_user_registration(self):
  self.client.get('/user/register')
  form = RegistrationForm(
    email=u'crow@crow.com',
    first_name=u'Alex',
    last_name=u'Frazer',
    username=u'crow',
    password=u'fake_password',
    confirm_password=u'fake_password'
  )
  self.assertTrue(form.validate())

form.validate()上的断言错误失败了,但是我如何查看验证错误是什么?

The assertion error is failing on form.validate(), but how can I view what the validation errors are?

推荐答案

使用

errors

一个字典,其中包含每个字段的错误列表.如果表单为空 尚未验证,或没有错误.

A dict containing a list of errors for each field. Empty if the form hasn’t been validated, or there were no errors.

这篇关于如何查看WTForms验证错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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