【问题标题】:Django CSRF verification failed. Webhook payment systemDjango CSRF 验证失败。 Webhook 支付系统
【发布时间】:2022-02-01 18:05:48
【问题描述】:

我正在尝试为我的支付系统实施 webhook。我有一个到我的 webhook 视图的路径,这是一个简单的定义,其中打印了提供的 id。

用法是这样的

http://localhost:8000/api/mollie-webhook/?id=ExampleId

路径

# mollie webhook
path('api/mollie-webhook/', mollie_webhook, name='mollie_webhook'),

查看

def mollie_webhook(request):
    id = request.POST['id']
    print(id)
    return JsonResponse(data={"response": "Success!"})

我收到以下错误

CSRF verification failed. Request aborted.

【问题讨论】:

标签: python django django-rest-framework webhooks mollie


【解决方案1】:

使用 csrf_exempt 装饰器将视图标记为免于 CSRF 检查

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def mollie_webhook(request):
    id = request.POST['id']
    print(id)
    return JsonResponse(data={"response": "Success!"})

【讨论】:

    猜你喜欢
    • 2012-09-08
    • 2015-06-02
    • 1970-01-01
    • 2022-06-22
    • 2017-03-29
    • 2011-06-14
    相关资源
    最近更新 更多