0

I want to create a home view that is the same as a home view but does not cache it.

urlpatterns += patterns('django.contrib.flatpages.views',
    url(r'^$', 'flatpage', {'url': '/'}, name='home'),
)

Something like this

urlpatterns += patterns('django.contrib.flatpages.views',
    url(r'^$', 'flatpage', {'url': '/'}, name='home'),
    url(r'^new/$', never_cache('flatpage', {'url': '/'}), name='nocache_home'),
)

Clearly this won't work but does anyone know the trick which would enable this?

4

1 回答 1

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')
)
于 2013-03-30T14:08:40.497 回答