[Fixed]-Django can't access raw_post_data

43👍

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.

👤alecxe

Leave a comment