I want to load a particular view depending on the url, for example:
url(r'^channel/(?P<channel>\d+)/$', ---, name='channel_render'),
Depending on the channel passed into the url, I want to load a specific view file. I tried doing this:
def configure_view(channel):
print channel
urlpatterns = patterns('',
url(r'^channel/(?P<channel>\d+)/$', configure_view(channel), name='channel_render'),
But obviously the channel argument is not getting passed in. Is there any way to do this? The only other solution I can think of is loading a manager view and then loading the relevant view file from there. If this is the only way, how do I redirect to another view file from within a view?
I think the easiest way to do this is to load a view that functions as a tiny dispatcher, which calls the final view you’re interested in.
As far as how to do that, views are just functions that get called in a particular way and expected to return a particular thing. You can call one view from another; just make sure you’re properly returning the result.
You can load views from different files with
import.