Contents:
Requirements¶
Python 3.4+
Introduction¶
Knights Templater is a light-weight, super-fast template engine which compiles your templates into Python classes.
The syntax is based on Django’s DTL, but as it allows raw Python the need for filter piping has been obviated.
Quick Start¶
Compile and render a template from a string:
>>> import knights
>>> tmpl = knights.kompile('Hello {{ name }}, how are you?')
>>> print(tmpl({'name': 'Bob'}))
Hello Bob, how are you?
Load a template from a directory:
>>> from knights.loader import TemplateLoader
>>> loader = TemplateLoader(['templates'])
>>> tmpl = loader['index.html']
>>> tmpl({....})
...
Since WSGI wants an iterable for its content:
>>> content = tmpl._iterator(context)
Thanks¶
Many thanks to Markus Holterman for soundboarding many of my ideas.
See Green Tree Snakes for an excellent introductin to Python AST.
Logo provided by Cherry Jam