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?
NameError: global name '---' is not definedOther names are defined within the program (such as variables). If Python encounters a name that it doesn't recognize, you'll probably get this error. Some common causes of this error include: Forgetting to give a variable a value before using it in another statement.
The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.
You need to import the function reverse
:
For Django 2.0 and up:
from django.urls import reverse
For older Django:
from django.core.urlresolvers import reverse
It's specific to django, but it looks like you're trying to build a URL anyway, so it's probably what you want.
--Use this code in models.py
......
from django.urls import reverse
def get_absolute_url(self):
return reverse('url-name', kwargs={'pk':self.pk})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With