现在的位置: 首页 > 综合 > 正文

Cheetah

2012年10月07日 ⁄ 综合 ⁄ 共 4401字 ⁄ 字号 评论关闭

Cheetah is a Python-powered template engine and code generator. It can be used as a standalone utility or it can be combined with other tools. Cheetah has many potential uses, but web developers looking for a viable alternative to ASP, JSP, PHP and PSP are expected to be its principle user group.

Cheetah:

  • generates HTML, SGML, XML, SQL, Postscript, form email, LaTeX, or any other text-based format.

  • cleanly separates content, graphic design, and program code. This leads to highly modular, flexible, and reusable site architectures, shorter development time, and HTML and program code that is easier to understand and maintain. It is particularly well suited for team efforts.

  • blends the power and flexibility of Python with a simple template language that non-programmers can understand.

  • gives template writers full access to any Python data structure, module, function, object, or method in their templates.

  • makes code reuse easy by providing an object-orientated interface to templates that is accessible from Python code or other Cheetah templates. One template can subclass another and selectively reimplement sections of it.

  • provides a simple, yet powerful, caching mechanism that can dramatically improve the performance of a dynamic website.

  • compiles templates into optimized, yet readable, Python code.

Cheetah integrates tightly with Webware for Python (http://www.webwareforpython.org/): a Python-powered application server and persistent servlet framework. Webware provides automatic session, cookie, and user management and can be used with almost any operating-system, web server, or database. Through Python, it works with XML, SOAP, XML-RPC, CORBA, COM, DCOM, LDAP, IMAP, POP3, FTP, SSL, etc.. Python supports structured exception handling, threading, object serialization, unicode, string internationalization, advanced cryptography, and more. It can also be extended with code and libraries written in C, C++, Java and other languages.

Like Python, Cheetah and Webware are Open Source Software and are supported by active user communities. Together, they are a powerful and elegant framework for building dynamic web sites.

Like its namesake, Cheetah is fast, flexible and powerful.


Give me an example!

Here's a very simple example that illustrates some of Cheetah's basic syntax:

<html>
<head><title>$title</title></head>
<body>

<table>
#for $client in $clients
<tr>
<td>$client.surname, $client.firstname</td>
<td><a href="mailto:$client.email">$client.email</a></td>
</tr>
#end for
</table>

</body>
</html>

Compare this with PSP:

<html>
<head><title><%=title%></title></head>
<body>

<table>
<% for client in clients: %>
<tr>
<td><%=client['surname']%>, <%=client'[firstname']%></td>
<td><a href="mailto:<%=client['email']%>">
<%=client['email']%></a></td>
</tr>
<%end%>
</table>

</body>
</html>


What is the philosophy behind Cheetah?

Cheetah's design was guided by these principles:

  • Python for the back end, Cheetah for the front end. Cheetah was designed to complement Python, not replace it.

  • Cheetah's core syntax should be easy for non-programmers to learn.

  • Cheetah should make code reuse easy by providing an object-oriented interface to templates that is accessible from Python code or other Cheetah templates.

  • Python objects, functions, and other data structures should be fully accessible in Cheetah.

  • Cheetah should provide flow control and error handling. Logic that belongs in the front end shouldn't be relegated to the back end simply because it's complex.

  • It should be easy to separate content, graphic design, and program code, but also easy to integrate them.

    A clean separation makes it easier for a team of content writers, HTML/graphic designers, and programmers to work together without stepping on each other's toes and polluting each other's work. The HTML framework and the content it contains are two separate things, and analytical calculations (program code) is a third thing. Each team member should be able to concentrate on their specialty and to implement their changes without having to go through one of the others (i.e., the dreaded ``webmaster bottleneck'').

    While it should be easy to develop content, graphics and program code separately, it should be easy to integrate them together into a website. In particular, it should be easy:

    • for programmers to create reusable components and functions that are accessible and understandable to designers.
    • for designers to mark out placeholders for content and dynamic components in their templates.
    • for designers to soft-code aspects of their design that are either repeated in several places or are subject to change.
    • for designers to reuse and extend existing templates and thus minimize duplication of effort and code.
    • and, of course, for content writers to use the templates that designers have created.


How mature is Cheetah?

Cheetah is stable, production quality, post-beta code. Cheetah's syntax, semantics and performance have been generally stable since a performance overhaul in mid 2001. Most of the changes since October 2001 have been in response to specific requests by production sites, things they need that we hadn't considered.

抱歉!评论已关闭.