如何查看WTForms验证错误?

2024-03-29 13:29:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一些基本测试,但有一个测试失败了。在

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()上失败,但如何查看验证错误是什么?在


Tags: nametestselfformclientnewgetdef
2条回答

使用^{}

errors

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

您可以通过添加以下内容来打印错误:print窗体.errors.items(). 在

相关问题 更多 >