1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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')
)
|
More like this
- E-mail quoting filters and tags by ChipX86 5 years, 11 months ago
- Humanize lists of strings in templates by ChipX86 5 years, 11 months ago
- Cache Any Function by jeffwheeler 6 years, 2 months ago
- Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
- Manager introspecting attached model by ubernostrum 5 years, 2 months ago
Comments
How is that better than the following code: urlpatterns = patterns('', (r'foo/$', never_cache(myview)) )
#
buriy: less code. Just as different as to use patters('common.prefix', ...)
#
Yeah, I basically didn't want to have to put never_cache() around every single URL entry for my site's JSON API (of which there are 30 or so functions). Much easier to do it once and never touch it again.
#