代码之家  ›  专栏  ›  技术社区  ›  juanefren

擦除模板缓存

  •  0
  • juanefren  · 技术社区  · 15 年前

    我有一个Django应用程序,用户可以选择两种界面模式,这种模式会影响一些页面。。。对于那些页面,我使用不同的模板

    在网址.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(在我的自定义配置页面中)时,模式直到服务器重新启动(apache或windows)才会改变运行服务器.py是一样的)。

    我想这和缓存有关,但我找不到如何删除缓存。(每次配置模式已更改。)

    1 回复  |  直到 15 年前
        1
  •  3
  •   Daniel Roseman    15 年前

    进入模式网址.py是行不通的。这个 get 仅在首次导入文件时执行一次。

    改为在view函数中执行数据库工作。