Reputation: 111
I am currently stuck with POST requests in Django. I am trying to send a POST request from an external applications such as smartphones or Postman (not forms) to the rest framework. Get requests work just fine.
I went through many posts but couldn't resolve my issue. I tried to use request.body but always get an empty response. I used print(response.body) to print the output to the console and only get b'' back.
class anyClass(APIView):
def post(self, request):
print(request.body)
return Response({"id": 'anyClass',
"data": '1234',
})
How would I get the data from my request?
My post request sent with Postman: http://127.0.0.1:8000/test/v2/Api/anyClass?qrcode=100023&date=2018-11-27&time=08:00:00&value_1=17
Upvotes: 1
Views: 15715
Reputation: 51958
You can get the response in request.data
:
class anyClass(APIView):
def post(self, request):
print(request.data)
return Response({"id": 'anyClass',
"data": '1234',
})
Please see the documentation for details.
I think you are making wrong kind of usage of postman. Please see the screen shot regarding how to use it:
Upvotes: 10