Use Cheetah Templates with Google App Engine

Community help for Google App Engine has been less than stellar because nobody takes a moment to explain how to do the supposedly “basic” python stuff. It took me a long time but I finally figured out the process to install Cheetah Templates for use with Google App Engine.

Running the command above compiled and installed Cheetah templates into a new Cheetah subdirectory within my single Google App Engine application. For Mac the install path was similar to /Users/bart/myapp/Cheetah.

Now, you can import Cheetah in your Google App Engine project! In the Google Documentation example helloworld.py I would put the Cheetah include line near the top of the file with the other includes

from Cheetah.Templateimport Template

Then, to actually have a Cheetah Template return something, you would use something like this to the MainPage class to output the rendered template. This is a more complete example.

Let us assume that the logged in user is ‘Jeff’ for sample output. The rendered output would be:

<p>Jeff is using Cheetah</p>

Notes

If you have more applications you need to copy or re-install the Cheetah directory into each different application individually. You need to do this because the applications get deployed to Google servers and will not have access to each others’ libraries.

Google says that App Engine works with “Pure Python” extensions and the process is simply to upload your extensions with the app. Since I put the install in /path/to/myapp/Cheetah I presume you can put other extensions and/or frameworks in there as well. Just download the Python source and configure/compile them to go into the app’s folder.

Why Cheetah?

Why did I go through this? First, I do not like the Django templating system. I have gotten accustomed to Cheetah because I use it at work. Second, Django’s hardline stance is to separate logic from presentation. Yes, the Django approach works for many but I like running loops and instantiating usable variables within my templates, a luxury afforded by Cheetah. Finally, Cheetah’s syntax is much closer to regular Python than the Django template syntax.