2010-09-20 86 views
0

我有一个Django应用程序,用户可以在2种接口模式之间进行选择,该模式会影响这些网页一些网页...我使用不同的模板擦除模板缓存

在urls.py我有这样的事情:

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

然后我的看法是这样的:

@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} 

当用户(在我的自定义配置页)选择模式2,模式不会改变,直到服务器重新启动我的问题是(EIT她的apache或runserver.py是一样的)。

我觉得这做缓存的东西,但我找不到如何清除高速缓存。 (每次Config.mode改变。)

回答

3

获得在urls.py模式是行不通的。当文件首次导入时,get将只执行一次。

而不是数据库在视图函数中工作。

+0

+1。 'urls.py'只加载一次。它不是动态配置的最佳位置。 – 2010-09-20 07:03:07

+0

+1。我们有一个'startup.py',它由'urls.py'导入并用来包含一次性启动脚本。 – 2010-09-20 14:10:33