Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django条带错误:请求请求请求\u rbqdcsrevu8ad:必须提供源或客户_Python_Django_Stripe Payments - Fatal编程技术网

Python Django条带错误:请求请求请求\u rbqdcsrevu8ad:必须提供源或客户

Python Django条带错误:请求请求请求\u rbqdcsrevu8ad:必须提供源或客户,python,django,stripe-payments,Python,Django,Stripe Payments,我的条带支付视图出现以下错误: InvalidRequestError at /advertise/post/ Request req_rbwdcpSrc9U8AD: Must provide source or customer. 我只是从中复制了代码,所以我不确定它为什么不起作用 def pay(request, context): ad = get_object_or_404(AdvertisePost, hash=context['hash']) amount = ad

我的条带支付视图出现以下错误:

InvalidRequestError at /advertise/post/
Request req_rbwdcpSrc9U8AD: Must provide source or customer.
我只是从中复制了代码,所以我不确定它为什么不起作用

def pay(request, context):
    ad = get_object_or_404(AdvertisePost, hash=context['hash'])
    amount = ad.total_price * 100

    # Set your secret key: remember to change this to your live secret key in production
    # See your keys here: https://dashboard.stripe.com/account/apikeys
    stripe.api_key = "sk_test_exhH9odKfkT4mxzbtVxuJOBZ"

    # Token is created using Checkout or Elements!
    # Get the payment token ID submitted by the form:
    if request.method == "POST":
        token = request.POST.get('stripeToken')
        print('Token:', token) #prints None

        charge = stripe.Charge.create(
            amount=amount,
            currency='aud',
            description='Boosted Post',
            source=token,
        )

    context = {
        'amount': amount,
        'ad': ad
    }

    return render(request, 'advertising/pay.html', context)
以下是我的html中的表单:

<form action="" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_8rSK99eA02ntvemImQCeV6su"
    data-amount="{{ amount }}"
    data-name="My name"
    data-description="Example charge"
    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
    data-locale="auto"
    data-currency="aud">
  </script>
</form>

知道问题出在哪里吗


我用这个一次性付款。不保存客户或类似的东西。

我通过在

如果没有令牌,则验证失败,因此您需要在post数据中查找错误。检查点4;问题是,这个错误只是来自页面加载。我实际上没有提交签出表单,这可能是在我的本地开发服务器上,而不是HTTPS?啊,对了,所以它在
GET
上。脚本的
数据键
attr应该是您的公钥。但是您的示例与您在视图中放置的密钥不匹配。
数据密钥
是我的公钥吗?(我的django视图有我的密钥)。我更改了几个字母,以防它们是敏感的,但我肯定在html表单中使用pk,在django视图中使用sk——所有副本都是从条带粘贴的,它会自动将相关的键嵌入到它们的位置。