我想创建一个与主视图相同的主视图,但不会对其进行缓存。
urlpatterns += patterns('django.contrib.flatpages.views',
url(r'^$', 'flatpage', {'url': '/'}, name='home'),
)
像这样的东西
urlpatterns += patterns('django.contrib.flatpages.views',
url(r'^$', 'flatpage', {'url': '/'}, name='home'),
url(r'^new/$', never_cache('flatpage', {'url': '/'}), name='nocache_home'),
)
显然这不起作用,但是有没有人知道可以实现这一点的技巧?
答案 0 :(得分:1)
from django.conf.urls.defaults import url
from django.views.decorators.cache import never_cache
def never_cache_patterns(prefix, *args):
pattern_list = [], tterns,
for t in args:
if isinstance(t, (list, tuple)):
t = url(prefix=prefix, *t)
elif isinstance(t, RegexURLPattern):
t.add_prefix(prefix)
t._callback = never_cache(t.callback)
pattern_list.append(t)
return pattern_list
urlpatterns = never_cache_patterns('',
(r'foo/$', 'myview')
)