Generic interface for Python template engines
Project description
collective.templateengines is an pluggable template language backend manager for Python. It defines generic interfaces which abstracts template language basic interfaction.
Template Backend helps you to achieve
Easy, pluggable, template language switching
Clean your codebase from template language dependencies
Motivation
All template engines have their shortcomings. Sooner or later you want to try yet another of them, or someone else wants to use another template engine with your project. This product is aimed to make that transition as smooth as possible, maybe just one line change.
Features
EGG deployment and easy install support (PyPi repository)
Interfaces defined using standard Zope interfaces package
Backends for: Django template Language, Cheetah
Unit test suite
Usage
The following example shows how one can switch between Django and Cheetah template engines with one line of change. Naturally, the templates themselves need to be refactored.
Cheetah:
from collective.templateengines.backends import cheetah engine = cheetah.Engine() context = DictionaryContext({"foo":"bar"}) template, syntax_errors = engine.loadString("Show variable $foo", False) result, evaluation_errors = template.evaluate(context)
Django:
from collective.templateengines.backends import djangotemplates engine = djangotemplates.Engine() context = DictionaryContext({"foo":"bar"}) template, syntax_errors = engine.loadString("Show variable {{ foo", False) result, evaluation_errors = template.evaluate(context)
TODO
Generic mechanism to register template tags
Secure context support (Zope, Plone)
Problems
Cheetah architecture lacks separate exposed compiling and evaluating phases
Cheetah exposes the full Python namespace to templates by default, making it hard to secure it
Cheetah cannot traverse Zope functions or attributes
Examples
Python Template Engines is used in
Easy Template product for Plone.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for collective.templateengines-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9ab947c954c2ce39f617778d41c6ecc65252fdf6c691c6f2276ad1c02a1f226 |
|
MD5 | 34c29605d9919e9d29c312e44cd5654c |
|
BLAKE2b-256 | 01378785f8b936dee65d9e8fd8666d8240700191a0abf874d325eb9f0afe2028 |