- July 25, 2007
- 4 (after 4 ratings)
This takes advantage of a recently added feature to django, being able to give it real functions as the view instead of having it be a string that is has to look up itself.
It takes advantage of how decorators work and how
cache_control works, normally you'd do something like this:
@cache_control(private=True, public=False) def view_stuff(request): # ... return response
Which is equal to doing
view_stuff = cache_control(private=True, public=False)(view_stuff) after definition.
cache_control is a function factory, more or less, which we use to our advantage.
1 2 3 4 5 6 7 8 9 10 11
from django.views.decorators.cache import cache_control from someproj.someapp.views import foo_view # ... open_cache = cache_control(private=True, public=True) urlpatterns = patterns('', (r'^foo/$', open_cache(foo_view)), # ... )
More like this
- Serializer factory with Django Rest Framework by julio 5 months, 3 weeks ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 6 months, 1 week ago
- Help text hyperlinks by sa2812 7 months, 1 week ago
- Stuff by NixonDash 9 months, 2 weeks ago
- Add custom fields to the built-in Group model by jmoppel 11 months, 2 weeks ago