清除模板缓存
我有一个 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(在我的自定义配置页面中)时,模式不会更改,直到服务器重新启动(apache 或 runserver.py 相同)。
我认为这与缓存有关,但我找不到如何删除该缓存。 (每次 Config.mode 更改时。)
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/
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.)
, 'custom_view', {'template':'my_template.html', 'mode':mode} ),
)
Then my view is something like this:
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 urls.py 中获取模式是行不通的。
get
仅在文件首次导入时执行一次。相反,数据库在视图函数中工作。
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.