views:

879

answers:

6

I'm in the process of building a web application using cherrypy.

What template technology do you recommend I use?

+3  A: 

If you mean a templating engine, I've had some success using mako with cherrypy. They just seem to play nicely together.

Mako is extremely easy to get started with and customize, which is, I assume, also two of your major reasons for choosing cherrypy. The cherrypy official tutorial also uses mako, and you can see a simple sample application there.

Triptych
+4  A: 

I like Cheetah.

Jacob
I like it too, but the use of $ for variables makes it harder to include jQuery, Prototype, etc, in the page. Even though most of your JS should be in static .JS files, some invariably need to be in the HTML.
darkporter
+5  A: 

Do you mean View in MVC? I recommend you very nice template engine Jinja2.

Glader
A: 

There is also Genshi Their tutorial is based on using cherrypy

+1  A: 

I like Genshi.

One reason that I like it is simply that the XML syntax looks much cleaner to me when mixed with HTML versus the text-level syntax of the other popular templating engines. For example, it's nice to be able to stick a py:for attribute on to output a table versus nesting messy #if or whatever lines.

Another reason is that because it's based on XML and treats your HTML as XML, it guarantees that your markup is syntactically correct -- i.e. that tags are closed and properly nested, special characters are properly escaped, etc.. Other templating engines will simply treat your HTML as text and output whatever you give it without the extra santity checks.

The main disadvantage of Genshi is that it is much slower than the faster text-based engines. However, its performance should be good enough for most sites. Unless you have a site that has a special need to render text/HTML at a super fast rate, the readability and syntax checking that Genshi provides probably outweigh the performance hit.

Dave76
This is a good summary, and in line with my sentiment. The only thing I might add is because the syntax _uses_ XHTML instead of simply generating it, even the unprocessed templates can be used directly by other XML and XHTML tools. Some templates can even be opened in a browser directly and previewed. Furthermore, because it's correct XML, the templates can be easily generated by other engines or used to generate templates for other engines. I used Genshi to generate JSPX pages, and it was painless and elegant.
Jason R. Coombs
A: 

A Zen master would probably answer: "Yes".

If you are building a web interface I would choose an engine that provides readable markup templates such as Genshi does.

If you are building a rest server and need to return other types of data I would go with one of the more text oriented engines such as Cheetah or Mako.

For building HTML pages I prefer Genshi over Cheetah or Mako even if it's quite a bit slower. When returning JSON I rather prefer the faster text-based engines.

And because Cherrypy is engine agnostic you can use both if you need it.

Marc