Pythonic way of web-programming

Ian Bicking ianb at colorstudy.com
Wed Apr 16 16:58:12 EDT 2003


On Wed, 2003-04-16 at 03:18, Alex Martelli wrote:
> Possible, yes.  Feasible, I dunno.  Compare Cheetah and preppy, which
> both process templates to produce Python modules.  preppy does it in
> a very simple, rather Pythonic way -- inserting "directives" enclosed
> in {{...}} that are Python expressions or a few Python statements
> modified to have explicit endif/endfor/&c termination rather than
> relying on indentation.  Any Python programmer should have no problem
> understanding preppy in 10 minutes and then happily using e.g.
>     {{myobject.func()}}
> or
>     {{myobject['index']}}
> or
>     {{myobject.attr}}
> &c &c in a fully appropriate manner -- since by definition a Python
> programmer already understands perfectly the difference between
> calling a function (and KNOWS you need empty parentheses when you
> call a function without arguments -- something that keeps tripping
> beginners up, btw), indexing a container, accessing an attribute.
> 
> But suppose your design intention is different -- you want your
> templates to be maintained by NON-programmers, people which DO
> have problems understanding the differences between the above
> distinct concepts!  In Cheetah, the above constructs would be
>     $myobject.func
>     $myobject.index
>     $myobject.attr
> i.e., totally polymorphic.  The Cheetah designer, on the basis of
> a LOT of experience trying to have non-programmers maintain
> templates, believe this extreme polymorphism makes things VERY
> much easier for non-programmers (perhaps particularly ones that
> have some previous exposure to languageoids such as Javascript
> and VBScript that may also try to hide such differences...).

That's okay though, because both just need a namespace to evaluate in. 
Cheetah's handling of function calls and whatnot don't change its
interface, just the template language.  A DOM-like templating language
obviously needs a different interface, but otherwise all the other
templates basically take a namespace and are otherwise self-executing.

So a template needs a source text and a namespace, and probably a way to
indicate certain other options (say, some languages may have a
case-insensitivity option, but others won't -- Cheetah allows the
NameMapper stuff to be turned off, for instance, making it more like
preppy).  But there's still lots that they could share.

For a difference in interface, Cheetah takes a list of namespaces that
get folded together.  I haven't looked at preppy, but let's say it takes
a dictionary or a single namespace.  That's a different interface, but
it can be turned into one interface, and then both templating languages
will benefit.

  Ian







More information about the Python-list mailing list