Web Development with Python

Authors: Robert Forkel
Date: September 12, 2007
In this seminar we give an introduction to Web Application development, with a focus on the TurboGears framework - a web application stack for the python language.


We'll talk about

What's the Web?

The web is ...

... the HTTP-speaking part of the internet.

(which mostly speaks HTML, too.)

See also

Ok, so what's HTTP?

The Hypertext Transport Protocol

Note: No matter how many layers of abstraction a web applicatio is built on, HTTP is what goes over the wire.

HTTP is standardized in a RFC Unfortunately it shares the fate of (all?) other web standards: many applications only follow the letter but not the spirit of the law. (We'll come to the spirit later, it's called REST.)


Everybody knows:

HTTP is stateless

Why is this good?

Why is it bad?

Is it true?

Example of non-stateless protocol: ftp, e.g. the server has a notion of a current working directory. A tell-tale sign is the LOGOUT (QUIT) command, which is absent in HTTP.


Uniform Resource Locators:


The HTTP variety:



MIME Types

The Content-Types of the Internet:

Multipurpose Internet Mail Extensions Media Types

They specify how to interpret the body.

Top level media types (the stuff before the slash):

For details:


The Spirit of HTTP

What is REST?

REST is the web app architecture for friends of Leibniz:

HTTP is the best possible protocol for the web.

Do I need to know HTTP?

Short answer: YES!

Longer answer:

What's a webb app?

A web application is

What's the difference between a web service and a web application?

None that I'm aware of.

Web App History

In the following we take a look at the history of web apps:

HTTP server

The HTTP server

Programming Interface:


The Common Gateway Interface: An API for web applications provided by HTTP servers:

Web App Frameworks

Modern web application frameworks at least provide

but typically also

URL Mapping

URL mapping: The mechanism to get from request path to response.


Three options to get from programming language to target format:

  1. Put code in the target format: psp, php, asp, kid,
    • in the best case preserving the validity of the format.
  2. Write target format from code: quichote,
    • degrades target form to simple strings.
  3. Separate transformation language: xslt,
    • fine if you data happens to be xml, otherwise you need another conversion to create data in the correct format.

Web Dev and Python

A myriad of web application frameworks:

ZOPE, Django, TurboGears, WebWare, web.py, pylons, ...

Because it's so easy to build one in python!


TurboGears is a web app framework subscribing to the Model View Controller paradigm:

TurboGears embraces a best-of-breed philosophy of using/integrating external components.

URL Mapping in TG

Anatomy of a TG App

TurboGears provides a place for

and mechanisms to access all the above conveniently.

The Request Cycle

In the easiest case, request handling for the programmer means:

What TG does behind the scenes:

Where's the HTTP?

Request headers:

Response creation:



Easy Development


You want to have FireFox (2.x) and the following extensions: