Re: form.errors.as_json() returns a str - Django 1.8

2015-04-22 Thread Tom Evans
On Tue, Apr 21, 2015 at 4:57 PM, George L.  wrote:
> I'm trying to return errors to an ajax call but as_json() form method
> generates a string of a dict instead of a dict. JsonResponse accepts only
> dicts and if I set safe=False, JsonResponse tries to serialize the data as a
> string, which results in a corrupted data.
>
> Is this a bug or expected result?

Expected result. JSON is text, if it returned a dictionary, as_json()
wouldn't be a good name!

JsonResponse is a util for turning dictionaries into JSON, if you
actually have JSON strings, you could do something like this:

  json_rsp = HttpResponse(frm.as_json(), content_type='application/json')

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1LqCGu8hbCQEMt%2BN6ycLG%3DYS93WUtnzLjRNMXEjxypXEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


form.errors.as_json() returns a str - Django 1.8

2015-04-21 Thread George L.
I'm trying to return errors to an ajax call but as_json() form method 
generates a string of a dict instead of a dict. JsonResponse accepts only 
dicts and if I set safe=False, JsonResponse tries to serialize the data as 
a string, which results in a corrupted data. 

Is this a bug or expected result?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f81f356-cb5d-47f1-a3dd-c8fc21a66bea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.