Django can't access raw_post_data

I am experiencing a strange thing with Django, here is my

def api(request):
    return HttpResponse("%s %s" % (request.method,request.raw_post_data))

Now I make an HTTP POST with POSTMAN (small app for google chrome).

I set POSTMAN to make a POST request with 'test' in the raw field.

Django returns me 3 different thing (random):

Sometime Django returns 'GET' sometime nothing at all and sometime:

AttributeError at /
'WSGIRequest' object has no attribute 'raw_post_data'
Request Method: GET
Request URL:
Django Version: 1.6.2
Exception Type: AttributeError
Exception Value:    
'WSGIRequest' object has no attribute 'raw_post_data'
Exception Location: /home/spice_dj/spice/ in api, line 17
Python Executable:  /usr/bin/python
Python Version: 2.7.3
Python Path:    
Server time:    Wed, 12 Mar 2014 22:51:11 -0400
  1. Why Django returns me 'GET' when I clearly make a POST request?

  2. Why does it return me that error?

  3. Why it does not return me the 'test' that I set in the raw field?


According to django 1.6 deprecation timeline:

The attribute HttpRequest.raw_post_data was renamed to HttpRequest.body in 1.4. The backward compatibility will be removed – HttpRequest.raw_post_data will no longer work.

The motivation is described in the relevant ticket:

request.raw_post_data is a bad name. It has nothing to do with POST in particular, it's just the body of the HTTP request. This confuses users, and makes it look like Django doesn't understand how HTTP works. We should change the name to request.body and start a deprecation process.

Use request.body:

def api(request):
    return HttpResponse("%s %s" % (request.method, request.body))

Hope that helps.

Need Your Help

File upload doesn't work with AJAX in PrimeFaces 4.0/JSF 2.2.x - javax.servlet.ServletException: The request content-type is not a multipart/form-data

jsf primefaces jsf-2.2 glassfish-4

Important : The issue which is discussed in this thread has been fixed as of PrimeFaces 5.1 final (community release) released on Monday, October 6, 2014 (just a few minutes ago from now). I attemp...

What is the use of adding a null key or value to a HashMap in Java?

java null hashmap key

HashMap allows one null key and any number of null values. What is the use of it?