[Tutor] Why not to use include?

Kent Johnson kent37 at tds.net
Sun Jun 8 14:32:36 CEST 2008


On Sun, Jun 8, 2008 at 6:46 AM, Dotan Cohen <dotancohen at gmail.com> wrote:
> I am moving a website from php to python gradually. The first step is
> replacing the page headers and footers.

I'm not sure how you plan to do this. PHP programs are embedded into
web pages. Python web programs output the contents of the web page.
This is pretty different.

> Currently, each page begins
> with <?php include "header.php"; ?> which contains the <head> porton
> of the html and the html code to present the website name and logo.
> Each page ends with <?php include"footer.php"; ?> which includes a
> footer note and the closing body and html tags. Of course this is a
> generalization, but the point is that I need to do something similar
> in Python. Python discourages the use of includes

Python doesn't have anything that functions like an include to
incorporate a literal block of text from an external file. I guess you
could call that discouragement....

> , and I would like to
> know why so that I can either rethink my page strategy, or decide to
> go against the 'recommended practices'.

You should probably find a Python template package that uses syntax
similar to PHP. There is a comparison of three modern template
packages here:
http://lucumr.pocoo.org/cogitations/2008/01/01/python-template-engine-comparison/

A more complete list is here:
http://wiki.python.org/moin/Templating?highlight=%28genshi%29

If your website is complex you might also want to consider a full web
framework such as Django or TurboGears.

Kent


More information about the Tutor mailing list