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:
AlbertoPL
2009-07-21 12:53:36
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
2009-07-21 12:58:08
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
2009-07-21 13:10:19
Thanks a lot guys
Vicky
2009-07-22 05:45:55