PyMeld for html templates?

Richie Hindle richie at entrian.com
Fri Jan 19 16:18:17 EST 2007


[Sean]
> I wonder if anyone has any thoughts on PyMeld as a template
> system for churning out general websites?

I'm doing that (but then I would be wouldn't I? 8-)
http://www.mandant.net is an example - the content of each page comes
from a file containing just the content, the layout and sidebar are
defined in a template HTML file, and the navigation is built by a
Python script.  All that is pulled together using PyMeld into a set of
HTML files and deployed to the web server (there's no need to it on the
fly for that site, but you certainly could).

> I want for a URI request to mysite.com/info
> to pull in a layout.html template which will in turn be populated by
> the info.html template. [...]  how about PyMeld, any ideas on how
> to do it or whether it will even work as I've described?

You'd do something like this:

from PyMeld import Meld

LAYOUT = """<html><head><title id='title'>The Title</title></head>
<body><div id='info'>The page information goes here.</div>
<p id='footer>Copyright Me 2007.</p></body></html>"""

INFO = """<html><head><title id='title'>The real title</title></head>
<body id='info'><p>Here is the info, which would in the real world
be read from a file.</p></body></html>"""

page = Meld(LAYOUT)
info = Meld(INFO)
page.title = info.title._content
page.info = info.info._content
print page

Is that the sort of thing you had in mind?

-- 
Richie Hindle
richie at entrian.com




More information about the Python-list mailing list