Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't easily compare PHP and Python.</p> <p>PHP is a web processing framework that is designed specifically as an Apache plug-in. It includes HTTP protocol handling as well as a programming language.</p> <p>Python is "just" a programming language. There are many Python web frameworks to plug Python into Apache. There's <a href="http://code.google.com/p/modwsgi/" rel="nofollow noreferrer">mod_wsgi</a>, CGI's, as well as web application frameworks of varying degrees of sophistication.</p> <p>The "use to put PHP where I want" is not really an appropriate way to judge Python as language for building web applications.</p> <p>A framework (like <a href="http://pylonshq.com/" rel="nofollow noreferrer">Pylons</a>, <a href="http://www.djangoproject.com/" rel="nofollow noreferrer">Django</a>, <a href="http://turbogears.org/" rel="nofollow noreferrer">TurboGears</a>, etc.) separates the presentation (HTML templates) from programming from database access. PHP mixes all three aspects of a web application into a single thing -- the PHP language. </p> <p>If you want to switch from PHP to Python you must do the following.</p> <ol> <li><p>Start with no preconception, no bias, nothing.</p></li> <li><p>Start fresh with a tutorial on the framework you've chosen. Do the entire tutorial without comparing anything you're doing to PHP.</p></li> <li><p>Start fresh on solving your chosen problem with the framework you've chosen. Build the entire thing without comparing anything you're doing to PHP.</p></li> </ol> <p>Once you've built something using a Python-based web framework -- without comparing anything to PHP -- you can step back and compare and contrast the two things. </p> <p>Folks who ask questions like <a href="https://stackoverflow.com/questions/1300610/python-substr">Python - substr</a>, <a href="https://stackoverflow.com/questions/1219548/java-and-python-equivalent-of-phps-foreacharray-as-key-value">java and python equivalent of php&#39;s foreach($array as $key =&gt; $value)</a>, <a href="https://stackoverflow.com/questions/1031192/what-is-python-equivalent-to-php-server">what is python equivalent to PHP $_SERVER?</a> are sometimes trying to map their PHP knowledge to Python. Don't Do This.</p> <p>The only way to start using a Python web framework is to start completely fresh.</p> <hr> <p><strong>Edit</strong></p> <p>All Python web frameworks have some "presentation logic" capabilities in their template engines. This is a "slippery slope" where you can easily turn a simple template into a mess. Clearly, a simple <code>{% if %}</code> and <code>{% for %}</code> construct are helpful to simplify conditional and repetitive elements of an HTML template.</p> <p>Beyond that, it starts to get murky how much power should be put into the tag language.</p> <p>At one extreme we have PHP/JSP and related technologies where the template engine can (and often does) do everything. This turns into a mess. Is the middle are <a href="http://jinja.pocoo.org/" rel="nofollow noreferrer">Jinja</a> and <a href="http://www.makotemplates.org/" rel="nofollow noreferrer">Mako</a> where the template engine can do a great deal. At the other end is Django where the template engine does as little as possible to avoid mingling presentation and processing logic.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload