If you use Cheetah, please support the project and register by clicking here:


14.2.1 The Containment Approach

In the Containment approach, your servlet is not a template. Instead, it it makes its own arrangements to create and use template object(s) for whatever it needs. The servlet must explicitly call the template objects' .respond() (or .__str__()) method each time it needs to fill the template. This does not present the output to the user; it merely gives the output to the servlet. The servlet then calls its #self.response().write() method to send the output to the user.

The developer has several choices for managing her templates. She can store the template definition in a string, file or database and call Cheetah.Template.Template manually on it. Or she can put the template definition in a *.tmpl file and use cheetah compile (section 4.2) to convert it to a Python class in a *.py module, and then import it into her servlet.

Because template objects are not thread safe, you should not store one in a module variable and allow multiple servlets to fill it simultaneously. Instead, each servlet should instantiate its own template object. Template classes, however, are thread safe, since they don't change once created. So it's safe to store a template class in a module global variable.

If you use Cheetah, please support the project and register by clicking here: