Compile Django templates to CCompile Django templates to C.
CTemplate is a quick hack to demonstrate compiling Django templates to C via Cython. You can use a CTemplate object just as you would a regular Django Template object:
>>> t = CTemplate("Hello {{ name }}") >>> c = Context({'name': 'Rebon'}) >>> t.render(c) 'Hello Rebon'
Behind the scenes, the Template object is compiled via Cython to a shared object (hopefully) providing a faster render method for that template. If CTemplate encounters a node that it cannot compile directly to C, it is pickled and executed "dynamically" at run-time.
Speedups of at least 5X-10X should be expected, assuming you do not have any uncompiled template nodes. In contrast, Jinja2 claims a 2X speed increase, although I am grossly misrepresentating the project here.
Performance comparisons are rather biased towards Django - in a typical Django project the Template object is constructed on each render, degrading the performance by at least one order of magnitude.