Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to view WTForms validation errors?

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'[email protected]',
    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?

like image 296
corvid Avatar asked Jul 04 '14 16:07

corvid


People also ask

What is WTForms in flask?

Flask WTForms is a library that makes form handling easy and structured. It also ensures the effective handling of form rendering, validation, and security. To build forms with this approach, you start by creating a new file in our app directory and name it forms.py. This file will contain all the application forms.

What is err validation?

A validation error occurs when you have validation/response checking turned on for one of the questions and the respondent fails to answer the question correctly (for numeric formatting , required response).


2 Answers

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.

like image 85
alecxe Avatar answered Oct 19 '22 09:10

alecxe


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

like image 37
Jay Shah Avatar answered Oct 19 '22 08:10

Jay Shah