Python vs PHP

Valentino Volonghi aka Dialtone dialtone.##NOSPAM#$#$$# at gmail.com
Sat Oct 23 13:36:02 EDT 2004


Istvan Albert <ialbert at mailblocks.com> wrote:
> what you showed here is basically a workaround, a way to
> "trick" python that runs the templating engine into
> directly executing a statement ... not a wise choice ...

It's not a workaroud. It's there and you can use that. I can't see a
different way to execute code from a template without calling exec or eval.
Of course I may be wrong about this, if you can tell me how to.

ZPT does exactly the same, and Nevow provides everything for you to do it.
BUT Nevow doesn't ship with that renderer by default.

> Moreover why is it that the webpage is so
> eager to explicitly contradict this possibility?
>
> http://www.divmod.org/Home/Projects/Nevow/
>
> "Nevow includes the ability to load templates off disk...
> ... The attribute technique was inspired by the attributes
> used by ZPT. However, no actual code may be embedded in
> the HTML template"

Because you cannot do (e.g.):

<%for i in range(10): %>
        <tr>blahblahblah</tr>
</%for>

But as I showed you can embed code in the tag attribute, you simply have to
write the renderer yourself, since the Nevow way is not to have code
outside of the python source file.

There is even a guy who wrote a new templating system for Nevow that can
read templates made like this IIRC:

<div> {$slot} </div>

In order to do this, you 'simply' have to provide a loader object that can
translate from your template to a Stan Tree that Nevow can use to render the
page, so, looking at this, there can even be a possibility to write a
templating engine for Nevow where you can embed code in the template.

-- 
Valentino Volonghi aka Dialtone
Now running FreeBSD 5.3-beta7
Blog: http://vvolonghi.blogspot.com




More information about the Python-list mailing list