Question: Getting error- UnboundLocalError: local variable 'token' referenced before assignment

Question

Getting error- UnboundLocalError: local variable 'token' referenced before assignment

Answers 0
Added at 2016-12-20 13:12
Tags
Question

Getting this error while loading the checkout page. Using django framework and stripe.

stripe.api_key = settings.STRIPE_SECRET_KEY
def checkout(request):
    publishKey = settings.STRIPE_PUBLISHABLE_KEY
    if request.method == 'POST':
        token = request.POST['stripeToken']
        try:
          charge = stripe.Charge.create(
              amount=1000,
              currency="usd",
              source=token,
              description="Example charge"
          )
        except stripe.error.CardError as e:
          pass
    context = {'publishKey': publishKey}
    template = 'checkout.html'
    return render(request,template,context)
Answers to

Getting error- UnboundLocalError: local variable 'token' referenced before assignment

Source Show
◀ Wstecz