posted on: 2008-07-23 07:51:51
This is a very short article on a way to implement CherryTemplate. It includes a short example for including a path that is not in your 'python path' before runtime.

>If you know python and you are trying to get into web page design, you will find yourself overwhelmed by the number of choices. TurboGears, Django, and Twisted all offer you access to web framework, the difficulty lies in getting them to work behind apache.

Something I have found that works great for getting my python backed web pages up and running is CherryTemplate. It is simple, you do not need to worry about setting up an WSGI, or running the server application persistently.

There are two main things that you need to be aware of: getting apache to use your CherryTemplate rendering and getting CherryTemplate to find the file.

First, decide what the file extension will be for you template files.

I use .chy for html templates and .chx for xml templates. Then you configure your .htaccess

AddHandler cherry-template .chy
Action cherry-template /cgi-bin/

If you know the basic understanding of handlers and such then this will make sense. If you have access you can put it into your httpd.conf. Next to use cherry template you need the file, ""

#!/usr/bin/env python
import os,sys
import cherrytemplate
epage = "/home/webserver/public_html/edocs/404.html"
sys.stdout.write("Content-Type: text/html\r\n\r\n")
fn = os.environ.get("PATH_TRANSLATED","")
if os.path.exists(fn):
	sys.stdout.write(cherrytemplate.renderTemplate(file = fn))
	sys.stdout.write(cherrytemplate.renderTemplate(file = epage))

You do not need to "install" cherrytemplate per se'. It is a stand alone python file. Download the package and put the file "" into your cgi-bin directory. If you would prefere to put the file elsewhere, then you can add that directory to your path at runtime by including the following:

import sys

That works really well for putting including any sort of external python. Even though you are using python you really should remember to separate church and state so to speak. (Separate you code from your template where possible).


2008-07-23 08:02:10
The next step to this will be to get this technique to run as fcgi. Right now there are a few difficulties I am still working through. I am trying to use flup as a wsgi interface.