Django form errors. get the error without any html tags


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:


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


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