Python Templating

5 views
Skip to first unread message

Ben DeMott

unread,
Sep 20, 2010, 10:26:26 AM9/20/10
to GRPUG: Grand Rapids Python Users Group
Hopefully most of you know that there has been long debate on the
topic of Python Templating, and there are a LOT of intermediate
template languages as well as Python code generators as a consequence
of this debate.
Unfortunately (or Fortunately) depending on your view point - Python
does not support scripting tags so it cannot enter and leave the
interpreter to output plain text within loops and so forth. This is
mostly because Python was intended as an application language.
What this means however, is that that the task of separating
presentation logic from display logic in Python isn't as easy as most
of us would like. If you haven't used Python for web programming then
this topic probably doesn't really affect you in any way shape or
form; but if you do then hopefully this will be good news to you.

Over the weekend and last week myself and a few of my friends embedded
PHP into a Python module. Upon import of the module the PHP shared
object binary is initialized and can be used / re-used for the
duration of the Python program.
We are working on the logic to finish marshaling Python types to PHP
types in C, and displaying warnings properly between the two
languages.
After Marshaling is done I would like to write an integration specific
to Twisted/Twisted Web to serve PHP from twisted in an efficient
manner.

Hopefully this will offer a more robust, more maintained, and better
documented alternative to the 20+ template languages listed here:
http://wiki.python.org/moin/Templating.

I need to write a makefile and I'll try to get the source up on GITHUB
by next weekend.

Cheers!
-Ben DeMott

Dave Brondsema

unread,
Sep 23, 2010, 5:35:31 PM9/23/10
to gr...@googlegroups.com
Wow, sounds.. fun? Seems like it could be a challenge to make
php-on-python more robust than the simpler architectures (e.g. pure python).

We use Jinja2 and it's pretty well documented and robust.


--
Dave Brondsema : da...@brondsema.net
http://www.brondsema.net : personal
http://www.splike.com : programming
<><

Ben DeMott

unread,
Oct 19, 2010, 8:57:04 PM10/19/10
to GRPUG: Grand Rapids Python Users Group
Myself and my colleague Caleb Burns finished with the first version of
this software a few weeks back.
Congratulations to Caleb - as he did almost all of the PHP side
marshaling / api work, and dug through the messy undocumented PHP c-
api.
A Special thanks to those few souls that maintain the Python C API
Docs - what a superior language Python is in documentation and low-
level API consistency - this experience has been an eye opener.


If anyone wants to play with it I quickly wrote the readme, its full
of typos and mistakes I'm sure - but should get you headed in the
right direction.

I'll update the repo with more examples when I get a chance; bug me if
you need help.

http://github.com/bendemott/pyhp
> Dave Brondsema : d...@brondsema.nethttp://www.brondsema.net: personalhttp://www.splike.com: programming
>               <><

Ben DeMott

unread,
Oct 19, 2010, 9:31:01 PM10/19/10
to GRPUG: Grand Rapids Python Users Group
On the subject I should mention:
http://bitbucket.org/tavisrudd/throw-out-your-templates/src/tip/throw_out_your_templates.py

I disagree that pre-processing python and consuming retarted amounts
of memory to create a serialized representation of a view is a good
approach - but just shines some light on the problem in general :)
Reply all
Reply to author
Forward
0 new messages