I’m trying to implement a webhook for my payment system. I have a path to my webhook view, which is a simple definition where the provided id is printed.
The usage is like this
JavaScript
x
2
1
http://localhost:8000/api/mollie-webhook/?id=ExampleId
2
Path
JavaScript
1
3
1
# mollie webhook
2
path('api/mollie-webhook/', mollie_webhook, name='mollie_webhook'),
3
View
JavaScript
1
5
1
def mollie_webhook(request):
2
id = request.POST['id']
3
print(id)
4
return JsonResponse(data={"response": "Success!"})
5
I’m getting the following error
JavaScript
1
2
1
CSRF verification failed. Request aborted.
2
Advertisement
Answer
Use the csrf_exempt decorator to mark the view as exempt from CSRF checks
JavaScript
1
8
1
from django.views.decorators.csrf import csrf_exempt
2
3
@csrf_exempt
4
def mollie_webhook(request):
5
id = request.POST['id']
6
print(id)
7
return JsonResponse(data={"response": "Success!"})
8