django-phased is an implementation of a two-phase template rendering system to allow caching of pages that otherwise would be uncachable due to user-specific content that needs to be rendered (such as a signed-in notice in the corner of the page). This technique has been described in detail by Adrian Holovaty in this blog post.
To install django-phased, either check out the source from Github or install from PyPI:
Check out django-phased from GitHub and run python setup.py install in the source checkout
Run pip install django-phased.
To make django-phased tags available to your templates, add 'phased' to your INSTALLED_APPS.
Install the PhasedRenderMiddleware to enable second-phase rendering of templates.
If using Django’s caching middleware, use PatchedVaryUpdateCacheMiddleware to bypass the Vary: Cookie behavior of that middleware.
A common setup for middleware classes would be this:
MIDDLEWARE_CLASSES = ( 'phased.middleware.PhasedRenderMiddleware', 'phased.middleware.PatchedVaryUpdateCacheMiddleware', ... 'django.middleware.cache.FetchFromCacheMiddleware', )
See Settings for additional settings.
In order to use the phasedcache template tag you need to add 'django.core.context_processors.request' to the TEMPLATE_CONTEXT_PROCESSORS settings variable and use RequestContext when you render your templates. See the Django docs on how to use RequestContext in your views.
See phasedcache for details.