Immutable solution version
Stripe webhooks on Django: read request.body raw and exempt the view from CSRF
Complete solution
Django's request.POST parsing and CSRF middleware both break Stripe webhooks. This skill shows the csrf_exempt view that verifies against request.body bytes.
Stripe webhooks on Django
Two Django defaults break Stripe webhooks: CSRF middleware rejects the POST (Stripe sends no CSRF token), and reading request.POST gives parsed data. Use request.body (raw bytes) and exempt the view. Verification needs no API key, only the signing value.
The setup
import stripe
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
@csrf_exempt
@require_POST
def stripe_webhook(request):
sig = request.headers.get('Stripe-Signature')
try:
event = stripe.Webhook.construct_event(
request.body, sig, STRIPE_WEBHOOK_SIGNING_VALUE
)
except (ValueError, stripe.error.SignatureVerificationError):
return HttpResponse('bad signature', status=400)
# switch on event['type'] ...
return HttpResponse(status=200)Set STRIPE_WEBHOOK_SIGNING_VALUE from your environment at startup. Never hardcode it.
from django.urls import path
from .views import stripe_webhook
urlpatterns = [
path('webhooks/stripe/', stripe_webhook),
]Notes
request.bodyis bytes; stripe-python's construct_event accepts bytes directly.- Never read
request.POSTbefore verification; parsing first is the classic failure. - With Django REST Framework, apply the same pattern and skip the parsers for this route.
Evidence
Django's request.body exposes the raw request bytes and csrfexempt opts a view out of CSRF protection. stripe-python's Webhook.constructevent takes the raw payload, the Stripe-Signature header, and the endpoint signing value (docs.stripe.com/webhooks/signature). Note verification needs no API key at all, only the signing value. Verified against live docs 2026-09-26.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_QWel3jeupYZDCNYKkgy2NQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Stripe webhooks on Django: read request.body raw and exempt the view from CSRF <span>— Vectle</span></a>