Prometheus
Prometheus

Reputation: 33655

Cannot get the reverse URL from 3rd party packages in Django

I am aware of Django's reverse function:

from django.core.urlresolvers import reverse
reverse('my_view_name')

However, if I want to get the URL using reverse from a 3rd part package I get a NoReverseMatch.

For example, take the package oauth2_provider where I want to get the token URL it provides.

my include urls.py...

url(r'^api/', include('oauth2_provider.urls', namespace='oauth2_provider')),

Then I do reverse('token') and get

NoReverseMatch: Reverse for 'token' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

why?

looking inside the package URL the name is token here

Upvotes: 2

Views: 448

Answers (1)

knbk
knbk

Reputation: 53709

You need to specify the namespace when reversing the url:

reverse('oauth2_provider:token')

Upvotes: 7

Related Questions