ModuleNotFoundError:没有名为“stripe”的模块,即使我已经导入到我的views.py fle中
from django.shortcuts import render
from django.http import HttpResponse,HttpResponseRedirect
from django.conf import settings
import stripe
STRIPE_PUBLISHABLE_KEY1=settings.STRIPE_PUBLISHABLE_KEY
# Create your views here.
def testing(request):
return render(request,"login.html",{'key':STRIPE_PUBLISHABLE_KEY1})
def charge(request): # new
if request.method == 'POST':
charge = stripe.Charge.create(
amount=500,
currency='usd',
description='A Django charge',
source=request.POST['stripeToken']
)
return render(request, 'success.html')
总是显示错误 /charge/ 处的名称错误 名称“stripe”未定义
可能您的环境中还没有安装它,请尝试使用安装它 pip 安装条带 有关更多详细信息,请参阅文档 https://pypi.org/project/stripe/
您安装了 Stripe 吗?如果没有,请尝试:
pip install stripe
另一个原因可能是您正在使用 venv,但您安装了错误版本的 Python 模块。例如,比较这些:
# install to default Python version, which might be, say, 3.10
# ...and then you'll get module not found if you expected to install it to, say, 3.9.
pip install -r requirements.txt
# install the module for 3.9 explicitly
python3.9 -m pip install -r requirements.txt