• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created over 14 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple two-phase template rendering application useful for caching of authenticated requests

django-phased

Build Status

A 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.

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.

More Repositories

1

django-template-repl

A readline shell for the Django template language.
Python
116
star
2

django-socketio-example

an example of using Django with Socket.IO
Python
76
star
3

surlex

Surlex (Simple URL expression translator) - Language for URL matching and extraction
Python
72
star
4

yoloimport

Never see another ImportError
Python
63
star
5

django-qunit

django-qunit integrates the QUnit Javascript testing framework with Django.
JavaScript
54
star
6

django-smart-load-tag

An attempt to bring namespaces and more control to Django's {% load %} tag.
Python
49
star
7

django-inmemorystorage

A non-persistent in-memory data storage backend for Django.
Python
32
star
8

gevent-spider

A simple spider with a realtime web UI.
Python
28
star
9

pieshop

a Javascript client for RESTful APIs targeting django-tastypie
JavaScript
24
star
10

ven

Virtualenv management refined
Shell
13
star
11

lawrence-veggie

List of vegetarian/vegan restaurants in Lawrence, KS
9
star
12

snowman

2010 Django Dash entry
Python
8
star
13

butlertron

an IRC bot
Python
8
star
14

pyraid

python-fuse raid implementation useful for data recovery
Python
5
star
15

python-memcached

fork of python-memcached from http://www.tummy.com/Community/software/python-memcached/ original project does not updates
Python
3
star
16

gohttpbin

Go implementation of httpbin.org
Go
2
star
17

paint

Gevent-socketio example app (collaborative painting)
JavaScript
1
star
18

django-grappelli

Unofficial mirror of django-grappelli's Google Code SVN repository
JavaScript
1
star
19

commandq

Create simple command queue invoker/worker processes with UNIX pipes and file locks.
Python
1
star
20

django-gis-bug-example

Just here to demonstrate a bug. Move along please.
Python
1
star