-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request.<method> is empty with Django 1.5 #6
Comments
Hm, yeah this is a problem. I've played around here and I can't find any great solutions that don't feel really slimy. Any thoughts @croach |
@nick2k5 the explanation below is a little long winded and goes into an addition to the framework that would help alleviate some of the problems, so you can skip to the end to get the tl;dr version of the answer if you want. Basically, it looks like Django is moving more and more into the modern era of web development. In the past nearly everything sent to the server came via a form submission, so it was a fairly safe assumption that all data sent in an HTTP POST was of the format sent by an HTML form. However, that's no longer the case. It's now very plausible that data is sent to the server via an HTTP POST using any number of media types (e.g., JSON). With this new change, the maintainers of Django are basically saying that they are no longer making an assumption of what type of data is being sent, but instead they are relying solely on the So, given all of this, it looks like both Django and the framework are acting correctly. If you send data via an HTML form, the data will end up in the POST QueryDict since the default There is one thing that would be nice to add to the framework and that would be handlers for media types other than the ones that Django handles (i.e., file uploads and form submissions). So, for example, if you wanted to accept JSON data, the client could set the tl;dr This is the correct behavior. In the past Django has been too lax on how it handles POST data and has just assumed that all POST data comes from a form submission. This is no longer a valid assumption in this modern era of single page web apps and RESTful APIs, so Django has tightened its handling of POST data. To make sure that your data shows up in the POST QueryDict, simply make sure that the |
@croach Thanks for this. Looks like a reasonable requirement (to require the header be set appropriately) -- I will add this to the docs. |
@croach thanks for this. saved my day. Also learnt few bytes. |
Should this issue be closed? |
I guess it can now. |
Thanks a lot. |
In Django 1.5,
HttpRequest._load_post_and_files()
:If content-type doesn't start with "'multipart/form-data'" or "application/x-www-form-urlencoded", an empty QueryDict is set, it no more uses
request.body
.Django 1.4.5: https://github.com/django/django/blob/1.4.5/django/http/__init__.py#L380
Django 1.5.1: https://github.com/django/django/blob/1.5.1/django/http/request.py#L231
The text was updated successfully, but these errors were encountered: