![](/img/trans.png)
[英]Setting up a subscription with Stripe - Django-stripe-payments - Error TemplateDoesNotExist
[英]Django - Stripe. You did not set a valid publishable key. Error that comes up when trying to incorprate stripe payments on a django website
我在 django 書店網站上工作,似乎有條帶集成錯誤。 我有一個要求提供付款信息的訂單頁面(我現在正在使用測試 API)。 我收到同樣的錯誤“您沒有設置有效的可發布密鑰。使用您的可發布密鑰調用 Stripe.setPublishableKey()。”
訂單/views.py
from django.conf import settings
from django.views.generic.base import TemplateView
class OrdersPageView(TemplateView):
template_name = 'orders/purchase.html'
def get_context_data(self, **kwargs):
##Stripe.setPublishableKey('PUBLISHABLE_KEY')
context = super().get_context_data(**kwargs)
context['stripe_key'] = settings.STRIPE_TEST_PUBLISHABLE_KEY
return context
模板/訂單/采購.html
{% extends '_base.html' %}
{% block title %}Orders{% endblock title %}
{% block content %}
<h1>Orders page</h1>
<p>Buy for $39.00</p>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ stripe_key }}"
data-description="All Books"
data-amount="3900"
data-locale="auto">
</script>
{% endblock content %}
在您的 forms 中,您需要一個{% csrf_token %}
並form action
。
<form action="{% url 'charge' %}" method="post">
{% csrf_token %}
<h1>Orders page</h1>
<p>Buy for $39.00</p>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ stripe_key }}"
data-description="All Books"
data-amount="3900"
data-locale="auto">
</script>
</form>
此外,除非從未在模板中設置定價,否則這是自找麻煩。 將它們設置在您的視圖中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.