Django form errors. get the error without any html tags

djangodjango-forms

I would like to get on my template the errors of the form in non-html version.

by default the error is wrap up by <ul class="errorlist"> which I want to avoid.

Anyway to do it without a massive code change ?

Best Solution

There are two new methods in Django 1.7 that would also be useful to solve this problem:

Form.errors.as_data()

>>> f.errors.as_data()
{'sender': [ValidationError(['Enter a valid email address.'])],
'subject': [ValidationError(['This field is required.'])]}

Form.errors.as_json()

>>> f.errors.as_json()
{"sender": [{"message": "Enter a valid email address.", "code": "invalid"}],
"subject": [{"message": "This field is required.", "code": "required"}]}