PylonsHQ.

Layout: Fixed-width

Pylons for PHP Users

Skip to end of metadata
Go to start of metadata
Unknown macro: {metadata-list}
Name Pylons for PHP Users
Space Pylons CookBook
Page Pylons for PHP Users
Section Home
Version 1.0
Status Draft
Reviewed False
Author(s) Mike Orr

This page tries to explain Pylons in terms familar to PHP users, and describes the specific differences between PHP and Pylons. Or at least it will when it's finished.

 High-level overview

 A web framework at its core has one basic responsibility: produce an HTML page with HTTP headers according to the URL requested.  Different frameworks do this in different ways:

  • Apache has a simple dispatcher that maps a URL to a file in a directory, and sends that file.
  • PHP is file-based.  It relies on Apache's dispatcher to find a specific .php file, and then "executes" it to produce the HTML.
  • Pylons handles the dispatching all on its own, via Routes (a Python library). Apache forwards the request to a running Pylons application.  Pylons uses Routes to determine which method to call in which controller class, based on the URL.  This method returns an HTML page as a string.  Pylons adds the HTTP headers and forwards the result to Apache.

A template is like a form letter.  "Dear Mr ___ : I am an accountant at __ Bank in Nigeria.  The __ of __ was killed in a politically-motivated assasination and left behind $ __ in an untraceable account.  I need your help to get this money out of the country away from corrupt ___ officials."  A template engine fills in the blanks and produces a finished document.  Mako, Genshi, Cheetah, and others are widely-used template engines in Pylons applications.  PHP applications frequently use Smarty templates for the same purpose.

A key difference is that in PHP your code is embedded in the HTML page, whereas in Pylons your code produces your HTML.  It can do that by returning a string, but most often it will invoke a template to produce the string.

Static (non-changing) files like images and stylesheets may be served directly by Apache outside Pylons, or by placing those files in a special "public" directory in your Pylons application.


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Powered by Pylons - Contact Administrators