We have Python middle-tier for our Web App . Now we need to render 3 different HTMLs...

  • for older browsers (simple read-only interface)
  • for HTML5 browsers (LOT more complex than older browsers)
  • for mobile website (simple XHTML-MP)

Now, we need to keep the Python middle-tier completely independent of any HTML -- just pure business logic.

So, we think we should use a PHP layer on top of Python to generate these HTMLs. PHP would talk to Python via SOA.

First -- is this a good idea? And if not, can you suggest a better design?

Second, if this is a feasible design -- do you think PHP+Python is good (maintainable) mix. If not, how about replacing the PHP layer by yet another Python layer.

Just remember that our middle-tier needs to be COMPLETELY isolated from any HTML thingy :)

-- UPDATE --

The reason we're inclined to using PHP is...

  • PHP itself is just a template engine embedded into HTML -- and it is SO easy to generate complex HTML with it. On the other hand, Python is more of a general purpose language and generating HTML with it will require us to use a third party library which will entail maintenance/upgrade/security hassles. Generating HTML is a sort of raison d'être for PHP.
  • Secondly, Python support for Nginx is NOT as good as PHP.
  • Actually, writing for HTML5 browsers is much simpler than writing for older ones - standardization is much better these days, and much of what used to require hacks and complicated scripts is now part of HTML/CSS itself. – tdammers Jul 24 '11 at 15:27
  • i agree -- but that's NOT the issue here -- the issue is what should we use as our view engine :) – treecoder Jul 24 '11 at 15:31
  • If you have already settled with Python as "middle-tier layer", it doesn't sound terribly intuitive to me to use PHP for the presentation. Maybe explain why this was your first idea? – phant0m Jul 24 '11 at 15:42
  • updated the original question answering why we're inclined to PHP. – treecoder Jul 24 '11 at 16:28

There's at least half a dozen very decent template engines for python. Compared to these, PHP is mediocre at best, and it's full of security gotchas. The CherryPy project (which, by the way, is a simplistic yet excellent web programming framework) has a page on template engines. Most of the options listed there should work without cherrypy though. You may also want to consider django.

Either choice will allow you to have two layers talking to each other through some kind of web service layer.

  • 1
    +1. As a templating engine, i am not aware of a single feature, PHP provides which, say, jinja2 doesnt. – keppla Sep 13 '11 at 6:47
  • PHP has a bunch of "features" that typical template engines don't, but most of them are actually misfeatures, at least in a templating context. – tdammers Sep 13 '11 at 6:59
  • 1
    All templating languages i know have equivalents for <?php echo $var ?> (in jinja {{ var }}), the typical loop constructs, some method for inclusions or modules. Most of them allow for inline code, too, even though it is often strongly frowned upon. So what are the features you are referring to, php has (regardless of their supposed flaws)? – keppla Sep 13 '11 at 7:18
  • Way, way, way too many to mention - just the worst parts: broken session API; GET, POST, COOKIE etc. available as globals, anywhere; messy output model ("headers already sent", anyone?); misguided security "fixes" (mysql_real_escape_string, addslashes, magic_quotes, strip_tags, "safe mode", ...) – tdammers Sep 13 '11 at 7:22
  • 1
    just because this distinction wasnt made by zend it does not mean we can identify parts of php which provide features used for templating, and discuss them under the aspect of templating only. – keppla Sep 13 '11 at 8:09

Your Answer

