【发布时间】:2015-09-30 21:54:11
【问题描述】:
我想在 heroku 上部署 dj-stripe 来处理我的付款。
1) 我已经创建了项目付款
2) 我已经安装了 dj-stripe 并在 INSTALLED_APPS 中包含了“djstripe”。
3) 接下来,我已经包含了 urlpattern
url(r'^stripe/', include('djstripe.urls', namespace="djstripe")),
4) 现在,当我转到 localhost:5000/stripe/ 时,它会重定向到 localhost:5000/accounts/login/?next=/stripe/,然后我的脸上就会出现这个错误
Using the URLconf defined in payment.urls, Django tried these URL patterns, in this order:
^admin/
^stripe/
The current URL, accounts/login/, didn't match any of these.
编辑:
根据文档,我已在项目的 settings.py 中添加了这些内容
STRIPE_PUBLIC_KEY = os.environ.get("STRIPE_PUBLIC_KEY", "<your publishable key>")
STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY", "<your secret key>")
and
DJSTRIPE_PLANS = {
"monthly": {
"stripe_plan_id": "pro-monthly",
"name": "Web App Pro ($25/month)",
"description": "The monthly subscription plan to WebApp",
"price": 2500, # $25.00
"currency": "usd",
"interval": "month"
},
"yearly": {
"stripe_plan_id": "pro-yearly",
"name": "Web App Pro ($199/year)",
"description": "The annual subscription plan to WebApp",
"price": 19900, # $199.00
"currency": "usd",
"interval": "year"
}
}
最后我运行了这些命令
python manage.py migrate
python manage.py djstripe_init_customers
python manage.py djstripe_init_plans
【问题讨论】:
-
看起来 djstripe 在其视图上使用了 LoginRequiredMixin,这意味着它需要一个活动会话才能显示其所有视图的一部分。由于您没有登录并且没有会话,它会尝试将您重定向到您没有处理的登录 url(“帐户/登录”)并且在其上找不到 url。
-
是的,他们使用 LoginRequiredMixin 类。您能否详细说明我应该如何解决这个问题?
-
好吧,LoginRequiredMixin 是一个可以添加到基本上说“除非您登录,否则您无法观看此视图!”的视图的混音。所以如果 djstripe 使用它,这意味着他们不希望匿名用户访问他们的视图。解决方案?集成用户/登录机制以满足这种需求。 docs.djangoproject.com/en/1.8/topics/auth
-
PS 你应该编辑你的问题标题。它太笼统了。
标签: django heroku stripe-payments