Question

I have a Django app where users can select between 2 interface modes, that mode affect some pages... for those pages I use different templates

In urls.py I have something like this:

mode = Config.objects.get().mode
urlpatterns = patterns('',
    url(r'^my_url/$', 'custom_view', {'template':'my_template.html', 'mode':mode} ),
)

Then my view is something like this:

@render_to()
def custom_view(request, template, mg=False, login=True):
    if mode:
        template = template + 'x' #I add an x to the template name to advice to django I that it should use the mode_2 template.
    return {'TEMPLATE':template}

My problem is when the user selects mode 2 (in my custom Configuration page), mode does not change until server is restarted (either apache or runserver.py is the same).

I think this has to do something with cache, but I can't find how to erase that cache. (each time Config.mode is changed.)

Was it helpful?

Solution

Getting the mode in urls.py is not going to work. The get will only be executed once, when the file is first imported.

Do the database work in the view function, instead.

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