Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codysoyland/django-phased
Simple two-phase template rendering application useful for caching of authenticated requests
https://github.com/codysoyland/django-phased
Last synced: 17 days ago
JSON representation
Simple two-phase template rendering application useful for caching of authenticated requests
- Host: GitHub
- URL: https://github.com/codysoyland/django-phased
- Owner: codysoyland
- License: other
- Created: 2010-06-13T23:20:08.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2015-08-17T08:02:13.000Z (about 9 years ago)
- Last Synced: 2024-10-13T21:11:58.063Z (about 1 month ago)
- Language: Python
- Homepage: http://django-phased.readthedocs.org/en/latest/
- Size: 224 KB
- Stars: 118
- Watchers: 5
- Forks: 12
- Open Issues: 10
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
django-phased
=============.. image:: https://secure.travis-ci.org/codysoyland/django-phased.png
:alt: Build Status
:target: https://secure.travis-ci.org/codysoyland/django-phasedA simple two-phase template rendering application useful for caching of authenticated requests.
How it works
------------This technique has been desribed by Adrian Holovaty `in this blog post`_
and previously by Honza Kral. The idea is to first render the template with
certain blocks denoted as "phased," such that they will not be rendered, and
will remain valid template code that can be rendered with a second pass.The second pass fetches the partially-rendered template from the cache and
performs a second render on it, using RequestContext to provide user-specific
context to the template. This enables very fast generation of pages that have
user-specific content, by bypassing the need to use the
``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting.This implementation uses a secret delimiter that makes it safe against the
possibility of template code injection vulnerabilities, as it only passes any
given text through the template parser once. The phased blocks can also contain
cached context... _`in this blog post`: http://www.holovaty.com/writing/django-two-phased-rendering/
Basic Implementation
--------------------django-phased contains a templatetag, ``phased``, which defines blocks that
are to be parsed during the second phase. A middleware class,
PhasedRenderMiddleware, processes the response to render the parts that were
skipped during the first rendering.A special subclass of UpdateCacheMiddleware that drops the "Vary: Cookie"
header from response when it updates the cache is also included, which, if
used in place of the standard UpdateCacheMiddleware will prevent the cache
middleware from varying the cache key based on cookies, thus enabling caching
of pages in authenticated sessions.