Reputation: 4566
I am using
rf['email'].errors
As said in docs, I can use it to have array of errors.
[str(e) for e in rf['email'].errors] #give me ["<django.utils.functional.__proxy__>"]
If repr or str - it gives ul's or string of array.
So it worked only when I used repr and eval together. But I think its stupid solution.
eval(`rf['email'].errors`)
Upvotes: 2
Views: 2040
Reputation: 97892
You have a couple options depending on the output you'd like.
Option one, use the unicode constructor to convert the data:
list_of_error_texts = [unicode(e) for e in rf['email'].errors]
(Django's proxy object implements a method that responds to unicode.)
Option two, get the ErrorList as text. This produces a newline separated list of error text, with each line preceded by an asterisk:
print rf['email'].errors.as_text()
* My error one
* My error two
Option three, use django's force_unicode function. This is like unicode
, but has some extra safety features:
from django.utils.encoding import force_unicode
list_of_error_texts = [force_unicode(e) for e in rf['email'].errors]
Upvotes: 2