Which template technology should I use with CherryPy? [closed]
Asked Answered
C

6

11

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

What template technology do you recommend I use?

Christinchristina answered 14/6, 2009 at 15:33 Comment(3)
huh? define "view technology"? Technically "a browser" would answer your question.Mucoprotein
Do you mean a templating engine?Etom
This wiki is a details (and hopefully up to date) answer to your question.Selfjustifying
A
5

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

Allaround answered 14/6, 2009 at 16:32 Comment(0)
I
5

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.

Inoffensive answered 14/6, 2009 at 16:27 Comment(0)
A
5

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

Allaround answered 14/6, 2009 at 16:32 Comment(0)
P
4

I like Cheetah.

Protestant answered 14/6, 2009 at 16:32 Comment(1)
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.Oversleep
S
3

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.

Spohr answered 15/6, 2009 at 1:8 Comment(1)
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.Sapiential
S
2

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.

Swanner answered 2/5, 2010 at 12:9 Comment(0)
C
0

There is also Genshi Their tutorial is based on using cherrypy

Cooler answered 14/6, 2009 at 19:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.