Previous topic

Next topic

This Page

Quick search

Since Cheetah supports two basic modes: dynamic and precompiled templates, you have
a lot of options when it comes to utilizing Cheetah, particularly in web environments.

There is added speed to be gained by using pre-compiled templates, especially when
using mod_python with Apache. Precompiling your templates means Apache/mod_python
can load your template’s generated module into memory and then execution is only
limited by the speed of the Python being executed, and not the Cheetah compiler.
You can further optimize things by then pre-compiling the generated Python files
(.py) down to Python byte-code (.pyc) so save cycles interpreting the Python.

In order to compile this down to a Python file, you need to only execute the
cheetah compile hello.tmpl command. The results will be a Python file (.py)
which you can then treat as any other Python module in your code base.

Note: If you use the #implements directive, respond may not be your “main
method” for executing the Cheetah template. You can adjust the example above in
Figure 2 by using getattr() to make the lookup of the main method dynamic: