模板语法错误:在PayPal模板中没有名为braintree的模块?

3 投票
1 回答
2049 浏览
提问于 2025-04-17 09:59

我正在做一个销售产品的项目,想在我的Django应用中使用PayPal进行支付。但是我遇到了这个错误:

'billing_tags' 不是一个有效的标签库:加载 billing.templatetags.billing_tags 时出现 ImportError:没有名为 braintree 的模块

在我的 settings.py 文件中,我已经把 'paypal.standard.ipn' 加入了 INSTALLED_APPS,并设置了 PAYPAL_RECEIVER_EMAIL

当我在 Python shell 中检查时……

>>> from billing import get_integration
>>> get_integration("pay_pal")
<billing.integrations.pay_pal_integration.PayPalIntegration object at 0x9d41b0c>

这意味着它是正常工作的……

在我的 urls.py 文件中,我有这个:

from billing import get_integration
pay_pal = get_integration("pay_pal")
urlpatterns = patterns('',
    (r'^paypal-ipn-handler/', include(pay_pal.urls)),
)

在我的 views.py 中:

from billing import get_integration
from paypal.standard.forms import PayPalPaymentsForm
def booking_save_page(request, id):
.....
form = BookTicketForm(request.GET)
if form.is_valid():
    inst = Ticket.objects.create(
               date_select = form.cleaned_data['date_select'],
               product_name = product.name,
               quantity = form.cleaned_data['quantity'],
               totalcost = form.cleaned_data['totalcost'],
               price = form.cleaned_data['price'],
               first_name = form.cleaned_data['first_name'],
               last_name = form.cleaned_data['last_name'],
               contact = form.cleaned_data['contact'],
               product = product,
               client = client,
               trans_code = code,
               email = form.cleaned_data['email'],
               memo = form.cleaned_data['memo'],
               status = 'Pending',
               created = now,
               )
    pay_pal = get_integration("pay_pal")
    pay_pal.add_fields({
           "business": "ccfiel@gmail.com",
           "item_name": product.name,
           "invoice": inst.id,
           "notify_url": settings.BASE_DNS + "/paypal-ipn-handler/",
           "return_url": settings.BASE_DNS + str(client.id) + '/book/'+str(inst.id) +'/success/?booksaved=1',
           "cancel_return": settings.BASE_DNS + str(client.id) + '/?booksaved=0',
           "amount": inst.totalcost})
    form = PayPalPaymentsForm(initial=pay_pal)
    context = {"form": form}
    return render_to_response("pay_pay.html", context)
 ......

而我的模板 pay_pay.html 只有这个:

<h1>Pay Here</h1>
{{ form.render }}

我觉得问题出在我的视图中渲染 pay_pay.html 的部分……所以我才会遇到这个错误:

'billing_tags' 不是一个有效的标签库:加载 billing.templatetags.billing_tags 时出现 ImportError:没有名为 braintree 的模块

有没有人对我的情况有什么想法?

1 个回答

3

在终端里输入 pip install braintree,然后重新启动你的服务器。

撰写回答