Python
  Home arrow Python arrow Templating with Cheetah
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Templating with Cheetah
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2005-12-27


    Table of Contents:
  • Templating with Cheetah
  • Basic Templating
  • Compiling Templates
  • More Logic

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Templating with Cheetah
    ( Page 1 of 4 )

    Templating makes it easier to handle dynamic content on web pages. One of the better templating frameworks for Python is Cheetah. Keep reading to find out more.

    Introduction

    The creation of dynamic web content is made much easier by using templates. These templates include substitution variables that are replaced with the proper value when the content is delivered to the user. There are a number of languages and frameworks that offer templating to developers, but Cheetah is one of Python's frontrunners. It allows templates to be made and then converted into Python objects for use within Python applications, and it works with pretty much every Python framework. For example, Cheetah could start with a template that looks like this:

    $header
    Hello, $name. Your last visit was on $date.
    $footer

    Cheetah would then compile it into a module, and $header, $name, $date and $footer could be substituted for just about anything, complete with any bells and whistles. In this article, we'll examine Cheetah and what it has to offer to Python developers looking to simplify dynamic content generation.

    Installing Cheetah

    Cheetah may be obtained from SourceForge:

    http://sourceforge.net/project/showfiles.php?group_id=28961

    Simply unarchive Cheetah and install it:

    python install setup.py

    Windows users will likely want to take a few extra steps when installing Cheetah. The first is to rename the file cheetah since it does not come with any extension to identify it as a Python file. It's located in the Scripts directory of your Python installation. Simply rename it cheetah.py, and if you are dying to lose the extension, create a file in the same directory called cheetah.bat:

    cheetah.py %*

    Next, it is recommended that you obtain a file named _namemapper.pyd from SourceForge. It speeds up Cheetah on Windows:

    http://prdownloads.sourceforge.net/cheetahtemplate/_namemapper.pyd?download

    Place the file in the Lib/site-packages/Cheetah directory of your Python installation.

    You'll probably want to add Cheetah to your Path environmental variable, too. If you've never done anything like this before (and since this article is intended to be useful to people of various levels of experience), simply go to the Properties of My Computer, click the Advanced tab, and then click the Environmental Variables button. Then, add  a semicolon to Path followed by the path to cheetah's location. For example:

    ;C:\Python24\Scripts

    You'll want to make sure Python is there, too.



     
     
    >>> More Python Articles          >>> More By Peyton McCullough
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek