global name 'reverse' is not defined

Magic picture Magic · May 27, 2015 · Viewed 21.5k times · Source

I'm using the django-paypal library to use PayPal payments on my site.

Following the example, I have set the paypal_dict and added the form.

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/",

    }

However, I am getting the error global name 'reverse' is not defined I am using Python 2.7.9, what's going on?

Answer

TankorSmash picture TankorSmash · May 27, 2015

You need to import the function reverse:

from django.core.urlresolvers import reverse

You can read more about it here. It's specific to django, but it looks like you're trying to build a URL anyway, so it's probably what you want.

For Django > 2.0

from django.urls import reverse