I’m trying to create a url pattern that will behave like controller/action/id route in rails. So far here is what I have :
from django.conf.urls.defaults import *
import views
urlpatterns = ('',
(r'^(?P<app>\w+)/(?P<view>\w+)/$', views.select_view),
)
Here is my ‘views.py’:
def select_view(request, app, view):
return globals()['%s.%s', % (app, view,)]()
So far this hasn’t worked. I get a key error exception in the ‘globals’ function. Am I going in the right direction here?
Try something like this:
It is obviously oversimplified example, what you do is import
views.pyfrom your app and see if it hasviewfunction, and if it does execute that function giving request as the first argument.See some examples of how Django does it with
get_callableandautodiscovermethods.