+1 to providing a better way of accessing JSON encoded post data. -1 to it
being munged into request.POST - I feel this is unintuitive.

A nice possibility could be a simple piece of middleware which detects
`application/json` and attaches request.json as an attribute, if it can
decode it. This attribute could actually be made lazy so as not to
introduce any real overhead on other pages, or on views already decoding
the data directly from request.data.

There is a (somewhat stalled) ticket for a JsonResponse class at #17942 (
https://code.djangoproject.com/ticket/17942).


On 3 September 2013 06:30, Stefan Berder <sber...@gmail.com> wrote:

> Hi,
> I looked around the list and couldn't find any mention of this subject.
>
> In `django.http.request.HttpRequest._load_post_and_files()` there is
> explicit mention of two content type ('multipart/form-data' and
> 'application/x-www-form-urlencoded'), any other content type will get empty
> values for self._post.
>
> Given that a lot of user form interaction is now happening through
> 'XMLHttpRequest', I think that the 'application/json' content type should
> be supported. A lot of javascript libraries will use json as the default
> format:
> * angularjs: http://docs.angularjs.org/api/ng.$http, see "Setting HTTP
> Headers"
> * emberjs:
> https://github.com/emberjs/data/blob/master/packages/ember-data/lib/adapters/rest_adapter.js#L974
> * backbone: http://backbonejs.org/#Sync
> * jquery: http://api.jquery.com/jQuery.ajax/ (the only one using
> 'application/x-www-form-urlencoded' by default)
>
> I'm trying primarily to create a discussion on the subject and am ready to
> provide the code for it as I had to write it. This would help avoid hacks
> to handle the request object in my view.
>
> I know there are some apps to handle API construction (django-tastypie,
> django-rest, django-piston and certainly others) they use either request
> wrappers or request handling in their views.
>
> Stefan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to