问题描述
所以我正在尝试使用django在stripe中创建客户,根据stripe中的文档,代码stripe.Customer.create应该可以工作,但是它只是出现此错误,有人可以告诉我为什么会这样吗?
views.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
文件或一个模块。
,是的,您在 stripe
目录下有一个名为django braintree
的 软件包 。
\django braintree\stripe\sales\views.py
我们如何验证呢?
您可以通过检查模块的.__file__
属性来检查模块的 位置 。
import stripe
print(stripe.__file__)
^^^^^^^^^^^