I have a Django form which I'm validating in a normal Django view. I'm trying to figure out how to extract the pure errors (without the HTML formatting). Below is the code I'm using at the moment.
return json_response({ 'success' : False,
'errors' : form.errors })
With this, I get the infamous proxy object error from Django. Forcing each error into Unicode won't do the trick either, because then each of the errors' __unicode__
method will be called effectively HTML-izing it.
Any ideas?
EDIT:
For those interested, this is the definition of json_response
:
def json_response(x):
import json
return HttpResponse(json.dumps(x, sort_keys=True, indent=2),
content_type='application/json; charset=UTF-8')
question from:
https://stackoverflow.com/questions/986406/returning-pure-django-form-errors-in-json 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…