cgi, reusing html. common problem?

John M. Gabriele john_sips_teaz at yahooz.com
Thu Sep 1 19:53:10 EDT 2005


On Thu, 01 Sep 2005 13:12:14 +0100, Fuzzyman wrote:

> On Thu, 01 Sep 2005 03:10:07 -0400, "John M. Gabriele"
> <john_sips_teaz at yahooz.com> wrote:
> 
>>I'm putting together a small site using Python and cgi.
>>
>>(I'm pretty new to this, but I've worked a little with
>>JSP/servlets/Java before.)
>>
>>Almost all pages on the site will share some common (and
>>static) html, however, they'll also have dynamic aspects.
>>I'm guessing that the common way to build sites like this
>>is to have every page (which contains active content) be
>>generated by a cgi script, but also have some text files
>>hanging around containing incomplete html fragments which
>>you read and paste-in as-needed (I'm thinking:
>>header.html.txt, footer.html.txt, and so on).
>>
>>Is that how it's usually done? If not, what *is* the
>>usual way of handling this?
>>
> 
> Having a template and inserting dynamic values into it is very common.
> 
> You'll have more luck looking for  'python templating systems'.
> 
> I use a module called 'embedded code' - which is part of firedrop by
> Hans Nowak. See http://www.voidspace.org.uk/python/firedrop2/
> 
> Popular templating engines include Cheetah and TAL.
> 
> You can also roll your own basic one using the string method
> ``replace``. 


Thanks for the reply Fuzzy.

I'm going to try rolling my own. I found this *great* article:
http://www.devshed.com/index2.php?option=content&task=view&id=198&pop=1&page=0&hide_js=1

and it shows pretty much exactly what I think I want: separate
html files containing fragments of a complete page, then some
python code to read in the html fragment, and replace your
generated code with some placeholder.


> 
> I'm pretty sure their is an entry on the Python.org WIKI about
> templating.

Whoops. I ended up hitting this page first:
http://wiki.python.org/moin/CgiScripts
and now I'm sticking with it. :)

I like CGI. I want to keep things as simple as possible. :)

---John


> 
> All the best,
> 
> Fuzzy
> http://www.voidspace.org.uk/python
> 
> 
>>Thanks,
>>---John

-- 
--- if contacting via email, remove zees ---





More information about the Python-list mailing list