Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'd like to follow the RESTful pattern for my new django project, and I'd like to know where the parameters are when a PUT/DELETE request is made.

As far as I know, I only see GET & POST QueryDict in the request, no others. Is Django adding a new PUT or DELETE QueryDict regarding to the request, or does it add the parameters to GET or POST QueryDict ?

Thanks for your help.

like image 761
Cyril N. Avatar asked Feb 14 '11 16:02

Cyril N.


People also ask

What is request parameter in Django?

The request parameter is a HttpRequest object, which contains data about the request (see the docs for django 3.2). In your urls file, you are not calling the view. index function, just listing a reference to it.

How does Django handle request?

Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function.

Does Django support put?

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.

What is request method == post in Django?

The result of request. method == "POST" is a boolean value - True if the current request from a user was performed using the HTTP "POST" method, of False otherwise (usually that means HTTP "GET", but there are also other methods).


1 Answers

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:)

like image 146
Ni Xiaoni Avatar answered Sep 19 '22 00:09

Ni Xiaoni