Z
Z
zlodiak2020-01-01 17:03:25
Django
zlodiak, 2020-01-01 17:03:25

How to get value from body?

I'm sending a POST request from the front to the back. The backend uses the following version of django:

>>> import django
>>> django.VERSION
(1, 8, 7, 'final', 0)


The view that handles the request looks like this:

@csrf_exempt 
def login(request):
    result = request.body.decode("utf-8")
    print('-----', result)
    return JsonResponse({'isLogged': 'True'})


The console output looks like this:

System check identified no issues (0 silenced).
January 01, 2021 - 13:56:57
Django version 3.1.4, using settings 'qwe.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
----- 
[01/Jan/2021 13:57:00] "OPTIONS /login HTTP/1.1" 200 20
----- {"login":"we","password":"eeee"}
[01/Jan/2021 13:57:00] "POST /login HTTP/1.1" 200 20


It can be seen that an object with data came in the request. Please help me to get login value

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-01-01
@zlodiak

json.loads(result).get('login')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question