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.
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.
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.
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.
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).
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:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With