DRIVER=processor
MODALIAS=cpu:type:x86,ven0000fam0006mod0055:feature:,0000,0001,0002,0003,0004,0005,0006,0007,0008,0009,000B,000C,000D,000E,000F,0010,0011,0013,0017,0018,0019,001A,002B,0034,003A,003B,003D,0068,006F,0070,0072,0074,0075,0079,007F,0080,0081,0089,008C,008D,0091,0093,0094,0095,0096,0097,0098,0099,009A,009B,009C,009D,009E,009F,00C0,00C5,00C8,00E7,00EB,00EC,00ED,00F0,00F1,00F3,00F5,00F9,00FA,00FD,00FF,0114,0115,0120,0123,0124,0125,0127,0128,0129,012A,012B,012E,0130,0131,0132,0133,0134,0138,013C,013E,013F,0140,0141,0142,0165,024A,025A,025F,0282,02A1,02A4

 ?÷     *******************************
  HOWTO Use Python in the web
*******************************

:Author: Marek Kubica

.. topic:: Abstract

   This document shows how Python fits into the web.  It presents some ways
   to integrate Python with a web server, and general practices useful for
   developing web sites.


Programming for the Web has become a hot topic since the rise of "Web 2.0",
which focuses on user-generated content on web sites.  It has always been
possible to use Python for creating web sites, but it was a rather tedious task.
Therefore, many frameworks and helper tools have been created to assist
developers in creating faster and more robust sites.  This HOWTO describes
some of the methods used to combine Python with a web server to create
dynamic content.  It is not meant as a complete introduction, as this topic is
far too broad to be covered in one single document.  However, a short overview
of the most popular libraries is provided.

.. seealso::

   While this HOWTO tries to give an overview of Python in the web, it cannot
   always be as up to date as desired.  Web development in Python is rapidly
   moving forward, so the wiki page on `Web Programming
   <https://wiki.python.org/moin/WebProgramming>`_ may be more in sync with
   recent development.


The Low-Level View
==================

When a user enters a web site, their browser makes a connection to the site's
web server (this is called the *request*).  The server looks up the file in the
file system and sends it back to the user's browser, which displays it (this is
the *response*).  This is roughly how the underlying protocol, HTTP, works.

Dynamic web sites are not based on files in the file system, but rather on
programs which are run by the web server when a request comes in, and which
*generate* the content that is returned to the user.  They can do all sorts of
useful things, like display the postings of a bulletin board, show your email,
configure software, or just display the current time.  These programs can be
written in any programming language the server supports.  Since most servers
support Python, it is easy to use Python to create dynamic web sites.

Most HTTP servers are written in C or C++, so they cannot execute Python code
directly -- a bridge is needed between the server and the program.  These
bridges, or rather interfaces, define how programs interact with the server.
There have been numerous attempts to create the best possible interface, but
there are only a few worth mentioning.

Not every web server supports every interface.  Many web servers only support
old, now-obsolete interfaces; however, they can often be extended using
third-party modules to support newer ones.


Common Gateway Interface
------------------------

This interface, most commonly referred to as "CGI", is the oldest, and is
supported by nearly every web server out of the box.  Programs using CGI to
communicate with their web server need to be started by the server for every
request.  So, every request starts a new Python interpreter -- which takes some
time to start up -- thus making the whole interface only usable for low load
situations.

The upside of CGI is that it is simple -- writing a Python program which uses
CGI is a matter of about three lines of code.  This simplicity comes at a
price: it does very few things to help the developer.

Writing CGI programs, while still possible, is no longer recommended.  With
:ref:`WSGI <WSGI>`, a topic covered later in this document, it