Question

How can I get the view that a url maps to? For example:

urlpatterns = patterns('',
                       url(r'^login/$', 'registration.views.Login'),)

How can I use the string 'login/' to return registration.views.Login?

In case I'm not clear, I want to write a function that does the following (I'll call it foo):

>>> foo('login/')
<function Login at 0x010101010>
>>>

I'm writing a script that needs this. Thanks!

Was it helpful?

Solution

Okay, got it. This is how I did it:

>>> from django.core.urlresolvers import resolve
>>> foo = resolve('/login/')
>>> foo.func
<function Login at 0x010101010>
>>>

from https://docs.djangoproject.com/en/1.5/ref/urlresolvers/#resolve

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top