views:

27

answers:

1

Hi ! My problem is simple, I have an url, I would like to resolve it, but get the url 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/')
'overview_books'

Do you know any way to do this ?

+2  A: 

Use this snippet:

http://djangosnippets.org/snippets/1378/

example:

>>> from my_projects.tools import resolve_to_name
>>> print resolve_to_name('/some/url')
'app.views.view'
>>> print resolve_to_name('/some/other/url')
'this_is_a_named_view'

;)

patrick