- 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
- codigo alto nivel by MrRocklion 1 month ago
- Load template from specific app by Krzysiek555 1 month, 3 weeks ago
- PostgreSQL JSON subqueries by dolamroth 1 month, 3 weeks ago
- "Magic Link" Management Command by webology 6 months, 4 weeks ago
- Closest ORM models to a latitude/longitude point by simonw 6 months, 4 weeks ago