sebpiq sebpiq - 1 year ago 66
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 ?

Answer Source

Use this snippet (originally taken from;

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download