全局名称'reverse'未定义

Mag*_*gic 8 python django paypal django-paypal

我正在使用该django-paypal库在我的网站上使用PayPal付款.

按照示例,我设置paypal_dict并添加了表单.

paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": "10000000.00",
        "item_name": "name of the item",
        "invoice": "unique-invoice-id",
        "notify_url": "https://www.example.com" + reverse('paypal-ipn'),
        "return_url": "https://www.example.com/your-return-location/",
        "cancel_return": "https://www.example.com/your-cancel-location/",

    }
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误,global name 'reverse' is not defined我正在使用Python 2.7.9,发生了什么?

Tan*_*ash 27

您需要导入该功能reverse:

from django.core.urlresolvers import reverse
Run Code Online (Sandbox Code Playgroud)

你可以在这里阅读更多相关信息.这是django特有的,但看起来你正试图建立一个URL,所以它可能就是你想要的.

对于Django> 2.0

from django.urls import reverse
Run Code Online (Sandbox Code Playgroud)


小智 6

在Django2.0中:

from django.urls import reverse
Run Code Online (Sandbox Code Playgroud)