Django REST framework request data

2019-04-09 06:05发布

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条回答
一纸荒年 Trace。
2楼-- · 2019-04-09 06:20

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.

查看更多
登录 后发表回答