【发布时间】:2021-07-17 14:37:23
【问题描述】:
views.py
from django.conf import settings
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
import stripe
stripe.api_key = settings.STRIPE_SECRET_KEY
# Create your views here.
@login_required
def checkout(request):
publishKey = settings.STRIPE_PUBLISHABLE_KEY
if request.method == 'POST':
token = request.POST['stripeToken']
try:
stripe.Charge.create(
amount=1000,
currency="usd",
card=token,
description="Charge for test@example.com"
)
except stripe.CardError:
# The card has been declined
pass
# Create the charge on Stripe's servers - this will charge the user's card
context = {'publishKey': publishKey
}
template = 'checkout.html'
return render(request, template, context)
When i run my views.py gives me this error - MultiValueDictKeyError at /checkout/
"'stripeToken'"
here is my checkout.py
MultiValueDictKeyError at /checkout/
"'stripeToken'"
那是我的 checkout.py 请帮忙,我将不胜感激。 我最终建立了一个网站来接受付款,但是当我运行它时,我得到了那个错误,我认为它来自views.py,但我不确定是否想从一些djangonites或pythoners那里得到一些反馈,谢谢
【问题讨论】:
标签: python django stripe-payments