Reputation: 25
Is there an inverse method for Django's django.core.urlresolvers.reverse()
?
I want a function f(x)
such that f(django.core.urlresolvers.reverse('shadowfax')) == 'shadowfax'
.
Does anybody have anything to say on whether this would be a proper approach to writing unit tests for methods that call .reverse()
?
Upvotes: 1
Views: 641
Reputation: 998
An updated version.
from django.urls import resolve
resolve( "/test" ).url_name
Upvotes: 1
Reputation: 56477
Probably shocking:
django.core.urlresolvers.resolve( "/test" ).url_name
It is perfectly good way to use it and it is even recommend in the documentation:
https://docs.djangoproject.com/en/dev/ref/urlresolvers/
Upvotes: 2