python - Django 和 Stripe,模块 'stripe' 没有 'Customer' 成员

标签 python django frameworks stripe-payments payment

所以我正在尝试使用 django 在 stripe 中创建一个客户,根据 stripe 中的文档,代码 stripe.Customer.create 应该可以工作,但它只是出现这个错误,有人能告诉我为什么会这样吗?

View .py

from django.shortcuts import render, redirect
from django.urls import reverse
from django.http import JsonResponse

import stripe
# Create your views here.
stripe.api_key = "xxxx"

def index(request):
    return render(request, 'sales/index.html')

def charge(request):
    amount = 5
    if request.method == 'POST':
        print('Data', request.POST)

        stripe.Customer.create(
            email=request.POST['email']
        )

    return redirect(reverse('success', args=[amount]))

def successMsg(request, args):
    amount = args
    return render(request, 'sales/success.html', {'amount':amount})


回溯

Traceback (most recent call last):
  File "C:\Users\snin2\anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\snin2\anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\snin2\Desktop\django braintree\stripe\sales\views.py", line 17, in charge
    stripe.Customer.create(
AttributeError: module 'stripe' has no attribute 'Customer'
[18/Sep/2020 08:36:39] "POST /charge/ HTTP/1.1" 500 66773


最佳答案

此错误的唯一原因是您的项目目录中可能有一个stripe.py 文件或一个模块。

而且,是的,您在 django braintreestripe 的> 目录。

\django braintree<b>\stripe\</b>sales\views.py

我们如何验证这一点?

您可以通过检查 .__file__ 来检查模块的位置模块的属性。

import stripe
print(stripe<b>.__file__</b>)
           <b> ^^^^^^^^^^^</b>

引用资料

  1. Python Stripe: 'module' object has no attribute 'Charge' -- (StackOverlofw)
  2. AttributeError: 'module' object has no attribute 'Charge' -- (GitHub)

关于python - Django 和 Stripe,模块 'stripe' 没有 'Customer' 成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63951023/

相关文章:

python - 自定义 Django 命令的自定义位置

php - Kohana:有哪些替代方案?

c# - .NET 5.0 或 .NET Framework 3.5 用于在 Windows 7+ 上部署?

python - 当 Python 子进程获取数据时,Raspberry Pi 上 LCD 上每行末尾的字符错误

python - 使用python将一列转换为多行

python - 如何使用 pywinauto 将焦点移到 Treeview.item 上?

macos - 苹果视觉框架: detect smiles or happy faces with observations?

python - 将 Python 与 Tkinter 结合使用,如何根据选项菜单中选择的选项使按钮按下执行不同的操作?

django - 如何在基于类的通用 View 中访问RequestContext?

python - 如何使用 django-cms 创建多个菜单