How does django receive json data from post?

how to use js post to django data in django to receive
JS similar to this

str = "{"student":[{"number":"0","name":"a"}]}";
obj = JSON.parse(str);

look at the data in chrome like this

[student][0][number]:0
[student][0][name]:a

how do I receive it in django? Convert to dict?

Mar.13,2021

json.loads (request.body)


if request.method = = 'POST':

result = json.loads(request.body.decode()).get('ip')

request.body gets data of type bytes, which is first decoded to type str, that is, the result of request.body.decode () is a json string, then json.loads () is converted to a Python dictionary, and then the corresponding value

is obtained.

if you only receive POST data, use json.loads (request.POST) . Body contains the original byte type characters, so an error is reported. See django docs: https://docs.djangoproject.co.

Menu