[英]Django throwing error 404 while connecting with stripe webhook
Hey guys I am keep getting 404 error on while using Stripe webhook in my Django app.嘿伙计们,我在 Django 应用程序中使用 Stripe webhook 时不断收到 404 错误。 Really appreciate your help
非常感谢您的帮助
my urls.py我的网址.py
urlpatterns = [path('my_webhook/', views.my_webhook, name='my_webhook')]
views.py视图.py
@csrf_exempt
def my_webhook(request):
payload = request.body
event = None
try:
event = stripe.Event.construct_from(
json.loads(payload), stripe.api_key
)
except:
return HttpResponse(status=400)
if event.type == 'payment_intent.succeeded':
payment_intent = event.data.object
elif event.type == 'payment_method.attached':
payment_method = event.data.object
else:
print('Unhandled event type {}'.format(event.type))
return HttpResponse(status=200)
Error:错误:
[20/Jul/2021 14:28:36] "POST /my_webhook HTTP/1.1" 404 3816
Not Found: /my_webhook
Localhost details:本地主机详细信息:
stripe listen --forward-to localhost:8000/stripe/my_webhook/条带监听 --forward-to localhost:8000/stripe/my_webhook/
Thanks for comments guys.感谢评论的家伙。
I found the solution.我找到了解决方案。 While calling
stripe listen
I also need to mention my app name.在调用
stripe listen
我还需要提及我的应用程序名称。
Previously in stripe CLI I was using以前在我使用的条带 CLI 中
stripe listen --forward-to localhost:8000/my_webhook/
then I added my app name in it and it started working然后我在其中添加了我的应用程序名称并开始工作
stripe listen --forward-to localhost:8000/pred/my_webhook/
where "pred" is the name of my app其中“pred”是我的应用程序的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.