Python
  Home arrow Python arrow Templating with Cheetah
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
PYTHON

Templating with Cheetah
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2005-12-27

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · Hey, all,I know that a lot of people have heard of Cheetah, but I'm not sure all...
       · I believe it should be 'python setup.py install'.
       · file ( 'count.txt', 'r' ).write ( str ( count ) )should be file ( 'count.txt',...
       · [b]print quotation ( searchList = [{ 'quotation': quotation [0],'author':...
       · This article was nice to show the simplcity of Cheetah, but falls far short of being...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway