【发布时间】:2021-01-04 20:51:10
【问题描述】:
我在 docker 容器中使用 django。我用这个命令 docker-compose exec web pipenv install stripe==2.32.0 安装条带。这也给了我成功的信息。然后我做了 docker down 并重建。这是我的视图文件
# orders/views.py
import stripe
from django.conf import settings
from django.views.generic.base import TemplateView
from django.shortcuts import render
stripe.api_key = settings.STRIPE_TEST_SECRET_KEY
class OrdersPageView(TemplateView):
template_name = 'orders/purchase.html'
def get_context_data(self, **kwargs): # new
context = super().get_context_data(**kwargs)
context['stripe_key'] = settings.STRIPE_TEST_PUBLISHABLE_KEY
return context
def charge(request):
if request.method == 'POST':
charge = stripe.Charge.create(
amount=3900,
ncy='usd',
description='Purchase all books',
source=request.POST['stripeToken']
)
return render(request, 'orders/charge.html')
我遇到的错误
web_1 | File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
web_1 | File "<frozen importlib._bootstrap_external>", line 728, in exec_module
web_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
web_1 | File "/code/orders/urls.py", line 4, in <module>
web_1 | from .views import OrdersPageView
web_1 | File "/code/orders/views.py", line 2, in <module>
web_1 | import stripe
web_1 | ModuleNotFoundError: No module named 'stripe'
这是我的 pip 文件
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
django = "*"
psycopg2-binary = "*"
django-crispy-forms = "*"
django-allauth = "*"
pillow = "*"
stripe = "==2.32.0"
[requires]
python_version = "3.7"
我不知道我在这里做错了什么。如果有人知道或遇到过这个问题,请回答
【问题讨论】:
-
您能否编辑问题以包含您图片的
Dockerfile?您通常不会使用docker-compose exec安装软件包,因为一旦容器被删除(这是一个非常常规的操作),这些更改就会丢失。
标签: django docker django-views stripe-payments