About Reading Posted JSON Data
You can read JSON data posted to a Django view like this:
import json
from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def webhook_view(request):
if request.method == "POST":
try:
data = json.loads(request.body)
except json.JSONDecodeError:
return HttpResponseBadRequest("Sorry! Malformed JSON.")
# process data...
return HttpResponse("All done.")
return HttpResponseBadRequest("Only POST requests allowed.")
Tips and Tricks Programming Development Django 5.x Django 4.2 Django 3.2 JSON
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.