Author: Mike Orr
Installation
For best results use Pylons >= 0.9.5 with Cheetah >= 2.0rc8. Neither of these are released as of March 2007, but you can install the development versions in the meantime:
Advantages of Pylons 0.9.5:
- "paster make-config" no longer depends on obsolete Cheetah 1.0.
Advantages of Cheetah 2.0rc8:
You'll also need the TurboCheetah package ("easy_install TurboCheetah"). Change the last line in turbocheetah/cheetahsupport.py ('return str(tempobj)') to:
This not only works better with Unicode, it gives some support for "fragments" (see below).
Application configuration
In your application's middleware file (myapp/config/middleware.py) after the config.init_app() call, add this line:
Your controller methods will then look like this:
The template for this controller method would be myapp/templates/index.tmpl, containing "Hello, ${c.what}!"
Important: Your templates directory and any subdirectories must contain an __init__.py file, or TurboCheetah will not find the templates.
To avoid the "cheetah" argument in render_response, make Cheetah the default template. Do this by adding "config.template_engines = []" before the add_template_engine line in middleware.py. The first engine added is the default. Then your controller method can say 'return render_response("index")'.
Fragments
If you pass 'fragment=True' to render_response, the template is supposed to be rendered without any site decorations (i.e., inherited templates). Cheetah doesn't have this concept, but if you define a '#def fragment' method in your template, TurboCheetah will call that and use it as the fragment.
As you would probably like to take advantage of Cheetah's inheritance, you may refer to your mybasetemplate with
#extends myapp.templates.mybasetemplateIt's worth mentioning that Pylons (as of 0.9.5) won't take care to compile .tmpl files into .py classes, it's up to the developer to `cheetah-compile` every .tmpl or rely on tools as Make (as suggested here
).
Both could safe time from googling for <type 'exceptions.ImportError'>: No module named mybasetemplate errors.