如何查看 WTForms 验证错误?

cor*_*vid 5 python testing unit-testing flask wtforms

我正在编写一些基本测试并且测试失败。

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())
Run Code Online (Sandbox Code Playgroud)

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

ale*_*cxe 6

使用form.errors

errors

包含每个字段的错误列表的字典。如果表单未经验证或没有错误,则为空。