Is it possible to retrieve the request parameters of a HTTP PATCH request in Django? request.method == 'PATCH'
is recognised, but I struggle to retrieve the request payload. I've tried request.REQUEST.items()
, but this didn't contain any data. I know I could use Django-tastypie, but in this case, I would like to avoid it (and I supposed tastypie is using some Django methods to retrieve this data anyway).
I'm using Django 1.5.1.
To send a PATCH request to the server, you need to use the HTTP PATCH method and include the request data in the body of the HTTP message. The Content-Type request header must indicate the data type in the body. In this PATCH request example, we send JSON to the ReqBin echo endpoint to update the data on the server.
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).
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.
META contains all the metadata of the HTTP request that is coming to your Django server, it can contain the user agent, ip address, content type, and so on.
You can use a QueryDict class manually. This is class implemented in django and processing all text data received through http request.
Link on the docs: https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.QueryDict
And here is an example of usage:
from django.http import QueryDict
def home_view(request):
if request.method == 'PATCH':
data = QueryDict(request.body)
print data['your_field']
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