未定义全局名称“reverse”

新手上路,请多包涵

我正在使用 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/",

    }

但是,我收到错误 global name 'reverse' is not defined 我正在使用 Python 2.7.9,这是怎么回事?

原文由 Magic 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 727
2 个回答

您需要导入函数 reverse

对于 Django 2.0 及更高版本:

 from django.urls import reverse

对于较旧的 Django

 from django.core.urlresolvers import reverse

它是 django 特有的,但看起来您无论如何都在尝试构建一个 URL,所以它可能就是您想要的。

原文由 TankorSmash 发布,翻译遵循 CC BY-SA 4.0 许可协议

在 Django2.0 中:

 from django.urls import reverse

原文由 user9686872 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题