【问题标题】:how to view WTForms validation errors?如何查看 WTForms 验证错误?
【发布时间】:2014-07-04 16:12:46
【问题描述】:

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

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

【问题讨论】:

    标签: python unit-testing testing flask wtforms


    【解决方案1】:

    使用form.errors:

    errors

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-18
        • 2014-01-21
        • 1970-01-01
        • 1970-01-01
        • 2023-02-02
        • 1970-01-01
        • 2014-02-09
        相关资源
        最近更新 更多