48đź‘Ť
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.
4đź‘Ť
–Use this code in models.py
……
from django.urls import reverse
def get_absolute_url(self):
return reverse('url-name', kwargs={'pk':self.pk})
- Django: How to keep the test database when the test is finished?
- How to limit query results with Django Rest filters
- In Django ORM, "values" and "annotate" are not working to group by
- Enable PK based filtering in Django Graphene Relay while retaining Global IDs
1đź‘Ť
reverse
isn’t a builtin function in python. Presumably, it’s a function in some web framework for doing reverse-routing (getting a url path from a name). The notify_url
has to be a url in your application that Paypal will send notices to.
- How do I convert kilometres to degrees in Geodjango/GEOS?
- Django ManyToMany relation to 'self' without backward relations
1đź‘Ť
There is no builtin function reverse
in Python. (There is a reversed
, but I doubt it’s what you want.)
There is a reverse
function in Django. But you only get Django builtins in code that’s loaded as a Django view or similar; if you import or run this code in some other way, it won’t exist.
So, presumably, you’ve gotten something wrong earlier in the instructions, and aren’t actually creating a view. (The Django-PayPal instructions are clearly written for someone who’s already an experienced Django developer; if you don’t understand basic Django concepts you will probably need to work through the tutorials first.)
- Determine if an attribute is a `DeferredAttribute` in django
- Is it a good practice to use serializer as query parameters validators?
- Encoding gives "'ascii' codec can't encode character … ordinal not in range(128)"
- Django – CSRF token missing or incorrect
1đź‘Ť
The url for paypal-ipn is probably defined in django-paypal’s urls. I guess that importing django’s reverse will solve this problem.
from django.core.urlresolvers import reverse
0đź‘Ť
I followed this solution to “reverse not defined” problem, and I still had this mistake… I imported reverse in all my urls files, with no effect… Then I imported reverse into views.py files and my local server started to work…
The original solution to this message is right, but author didn’t mention where to post import reverse, so I thought may be I will complete the original answer… If somehow I am wrong, I apologize, but it worked for me…
- How to use normal Filter together with SearchFilter on Django Rest Framework?
- Pylint (pylint_django) does not work when –django-settings-module flag is specified
- Why does Django South require a default value when removing a field?