sebpiq sebpiq - 1 month ago 6
Python Question

Django 'resolve' : get the url name instead of the view_function

My problem is simple, I have an url, I would like to resolve it, but get the

name instead of the view function associated with it ...

For example... this is urlconf :

urlpatterns = patterns('',
url('^/books/$', book_list, name="overview_books"),

And this is what I would like :

>>> resolve('/books/')

Do you know any way to do this ?


Use this snippet (originally taken from;

>>> from import resolve_to_name
>>> print resolve_to_name('/some/url')
>>> print resolve_to_name('/some/other/url')