Web devel with python. Whats the best route?

Alex Martelli aleaxit at yahoo.com
Wed Jan 10 06:06:00 EST 2001


"Sam Penrose" <spenrose at well.com> wrote in message
news:spenrose-E755EB.22423209012001 at news.dnai.com...
    [snip]
> In contrast to Alex's comments, however, we do not place Python
> statements within HTML. We stick with string substitution keys,

That's nice, but in my very first application I needed to
generate a variable number of repetitions of a table-row,
depending on values computed from the Python side of things.

Rather than reinvent loop-syntax &c, I found it simplest to
embed a for statement in the HTML template, a la:

+for i in range(len(results)):
    <TR> <TD><B>@i@</B></TD> <TD>@results[i]@</TD> </TR>
-

All the presentation logic goes into the template, all of
the computation into the Python CGI script, and my little
yaptu.py (yet another python template utility, of course)
bridges the gap (with about 50 SLOC's, plus comments,
docstrings, and test pushing it to a bit over 100 lines).

[For the curious, it's just a 2K byte download from
http://aleax.supereva.it/Python/Yaptu.zip -- but I have
to apologize in advance for its quality, since it WAS
my first playing with Python, and back in 1.5.2 times].


> The next time someone posts to comp.lang.python telling you you really
> need an Apache module/Zope/whatever to handle that customer feedback
> page, don't believe them.

To be honest, I don't think anybody's really saying you
NEED fancy approaches, just that they're more convenient
than roll-your-own-on-top-of-CGI.  This may well be true
for big and complex sites, too -- my counterthesis is just
that many sites are simple ones needing no more than CGI
(and perhaps 50 SLOCs worth of a templating utility:-).


Alex






More information about the Python-list mailing list