Django - Where are the params stored on a PUT/DELETE request?

I am using django v1.5. And I mainly use QueryDict to solve the problem:

from django.http import QueryDict
put = QueryDict(request.body)
description = put.get('description')

and in *.coffee

$.ajax
      url: "/policy/#{policyId}/description/"
      type: "PUT"
      data:
        description: value
      success: (data) ->
        alert data.body
      fail: (data) ->
        alert "fail"

You can go here to find more information. And I hope this can help you. Good luck:)


I assume what you're asking is if you can have a method like this:

def restaction(request, id):
    if request.method == "PUT":
        someparam = request.PUT["somekey"]

The answer is no, you can't. Django doesn't construct such dictionaries for PUT, OPTIONS and DELETE requests, the reasoning being explained here.

To summarise it for you, the concept of REST is that the data you exchange can be much more complicated than a simple map of keys to values. For example, PUTting an image, or using json. A framework can't know the many ways you might want to send data, so it does the obvious thing - let's you handle that bit. See also the answer to this question where the same response is given.

Now, where do you find the data? Well, according to the docs, django 1.2 features request.raw_post_data. As a heads up, it looks like django 1.3 will support request.read() i.e. file-like semantics.


Ninefiger's answer is correct. There are, however, workarounds for that.

If you're writing a REST style API for a Django project, I strongly suggest you use tastypie. You will save yourself tons of time and guarantee a more structured form to your API. You can also look at how tastypie does it (access the PUT and DELETE data).