Django REST framework request data

2019-04-09 05:47发布

问题:

Im using DJango REST framework to write my web service layer in which I want to read request payload from the request (POST). I tried the following code but I get empty set

@api_view(['POST'])
def login(request):
    print request.POST

Content Type is JSON. I tried to pass data from REST Client Tool. Still am able to read header values but only Payload is not coming out.

回答1:

You should use request.DATA instead of request.POST to retrieve json data.

request.DATA has been deprecated in favor of request.data since version 3.0, and has been fully removed as of version 3.2.