[Tutor] Why not to use include?

Andreas Kostyrka andreas at kostyrka.org
Sun Jun 8 19:48:12 CEST 2008


On Sunday 08 June 2008 17:13:21 Dotan Cohen wrote:
> 2008/6/8 Kent Johnson <kent37 at tds.net>:
> > 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.
>
> Very little of the pages are PHP, most is HTML. I understand that
> Python can be used as a web scripting language, so I assume that
> Python can be run in Apache from a page with an .html extension. Is
> this not the case, with an .httaccess directive?

Generally no.

Furthermore, Python is pretty bad language to embed in HTML, as whitespace is 
significant in Python.

>
> >> 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....
>
> Could I do something similar with a function? Something like
> printHeader() and I would define that function in a class?

Consult http://wiki.python.org/moin/WebProgramming first, please ;)

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/tutor/attachments/20080608/75db6256/attachment-0001.pgp>


More information about the Tutor mailing list