P
P
Pan Propan2018-09-03 18:41:19
Django
Pan Propan, 2018-09-03 18:41:19

How to parse JSON from an incoming request?

1C sends a POST request. With JSON data in the request body.
How do I count them in Django?
Tried like this

@csrf_exempt
def data_fill(request):
    try:
        data = json.loads(request.body.decode("utf-8-sig"))  # Загрузка JSON
    except ValueError:
        return HttpResponse("invalid json")

An error is thrown.
django.http.request.RawPostDataException: You cannot access body after reading from request's data stream
Of course, I googled, Google refers to problems with CSRF, but it seems to have written @csrf_exempt before the view.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question