views:

183

answers:

2

In Django the {{ form.field.errors }} gives the validation error for a field. But it always displays it as unordered list (). But I just want the error message. Is there a way to get the error message?

+3  A: 

Use {% for error in field.errors %} and then output each error one by one, this will produce just the string containing the message rather than an unordered list. The docs explain this:

http://docs.djangoproject.com/en/1.0/topics/forms/

AlbertoPL
Also useful is {% for error in form.non_field_errors %} (which the docs don't mention) to get to the errors that aren't tied to a single specific field.
Steve Losh
Yea, I really wish the docs were better documented, they sometime leave something to be desired, even if the docs are pretty good for things that ARE documented.
AlbertoPL
Thanks a lot guys
Vicky
A: 

You can just use {{ form.field.errors|striptags }}.