how to view WTForms validation errors?

时光毁灭记忆、已成空白 提交于 2020-05-15 11:10:48

问题


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())

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


回答1:


Use form.errors:

errors

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




回答2:


You can print the errors by adding the following: print form.errors.items().



来源:https://stackoverflow.com/questions/24578039/how-to-view-wtforms-validation-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!