The global name "reverse" is undefined

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

Following an example , I set paypal_dict and added a 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 get the error global name 'reverse' is not defined I am using Python 2.7.9, what happens?

+5
source share
4 answers

You need to import the reverse function:

 from django.core.urlresolvers import reverse 

You can read about it here . This is specific to django, but it looks like you are still trying to create a url, so you probably want to.

+18
source

reverse not a built-in function in python. Presumably, this is a function in some web environment to perform reverse routing (getting the url on behalf of). notify_url must be the URL of your application that Paypal will send notifications to.

+1
source

Python has no built-in reverse function. (There is reversed , but I doubt what you want.)

Django has a reverse function. But you only get embedded Django in the code loaded as a Django view or the like; if you import or run this code in any other way, it will not exist.

So, presumably, you got something wrong earlier in the instructions and are not actually creating a view. (Django-PayPal instructions are clearly written for those who are already experienced Django developers, and if you do not understand the basic concepts of Django, you will probably have to work through tutorials .)

+1
source

The url for paypal-ipn is probably defined in the django-paypal urls. I assume importing django reverse will solve this problem.

 from django.core.urlresolvers import reverse 
+1
source

All Articles