Ajax POST not sending data when calling ‘request.POST’ in Django view

When posting JSON data with application/json you need to use request.body instead of request.POST.

Like so:

class VoteUpPost(View):
    def post(self, request):
        print(request.body)
        data = json.loads(request.body)
        return JsonResponse({'status': True})

Also as Jacques mentioned, make sure to update your js to pass a JSON string.

Change:

data: {'dane': 123456789101112},

To:

data: JSON.stringify({'dane': 123456789101112}),

Leave a Comment