Reputation: 829
How can I get JSON from request?I wrote codes,
@csrf_exempt
def get_json(request):
print(request)
return HttpResponse('<h1>OK</h1>')
but
print(request) print out WSGIRequest: POST '/app/get_json'. I wanna get json in this part.So I wrote
print(request.text)
but error happens.Why can't I get it?I think request has json data,but is it wrong?How can I do it?
Upvotes: 1
Views: 5629
Reputation: 10305
The raw HTTP request body as a byte string
. So use request.body
to get all the raw body datas and later convert to json.
json_body = json.loads(request.body)
Upvotes: 6