Home > Net >  receive the data passed in the body of the request API Django Python
receive the data passed in the body of the request API Django Python

Time:03-15

I want to get the data passed in the request body like : [1]: https://i.stack.imgur.com/V5s1e.png

My function look like :

def test(request):
        # I want recieve data from body here like
        data = functionRequestBody
        print(data)
        return HttpResponse()

CodePudding user response:

What information are you looking for? Try request.text, request.session, etc. If your app has users you can get the current user's info through request.user: ex request.user.pk returns the db entry's primary key, request.user.username will return username.

https://www.javatpoint.com/django-request-and-response

CodePudding user response:

The answer is request.body . I find a better answer on another post StackOverflow

body_unicode = request.body.decode('utf-8')
request = json.loads(body_unicode)

(warning : ended your endpoint with a "/" else is not working) Thx Raphael for your comm !

  • Related