Project

General

Profile

Wiki » History » Version 6

Jan Klopper, 2012-02-20 16:49

1 6 Jan Klopper
!uweb_inernals.png! 
2 1 Elmer de Looff
h1. µWeb
3 1 Elmer de Looff
4 1 Elmer de Looff
µWeb is a Python software package designed to provide a flexible, lightweight, but powerful base to build web applications on top of. It can tie in to mod_python for Apache, or run stand-alone, using Python's included @BaseHTTPServer@ package.
5 1 Elmer de Looff
6 1 Elmer de Looff
µWeb provides an MVC like environment, built around three core philosophies:
7 1 Elmer de Looff
# as little boilerplate as possible;
8 1 Elmer de Looff
# as little Magic™ as possible;
9 1 Elmer de Looff
# and separation by convention, not brute force.
10 3 Elmer de Looff
11 1 Elmer de Looff
These philisophies overlap more than a little with the "Zen of Python":http://www.python.org/dev/peps/pep-0020/#content, which is not a coincidence.
12 1 Elmer de Looff
13 1 Elmer de Looff
h2. Components
14 1 Elmer de Looff
15 1 Elmer de Looff
µWeb is a framework that consists of mix of components building from a low-level standalone server on top of @BaseHTTPServer@ to a refined template parser and database abstraction model.
16 1 Elmer de Looff
17 1 Elmer de Looff
h3. Request Router
18 1 Elmer de Looff
19 5 Elmer de Looff
The *[[Request Router]]* is the entry point of the µWeb framework. Any HTTP request seen by the server is passed through here, from which it is delegated to the proper handler.
20 1 Elmer de Looff
21 1 Elmer de Looff
22 1 Elmer de Looff
h3. PageMaker and Response (_Controller_)
23 1 Elmer de Looff
24 5 Elmer de Looff
*[[PageMaker]]* provides the controller part of the MVC approach. Each web request ends on a specific method of the PageMaker. From here, request information can be viewed (cookies, query arguments and POST data), and databases used to gather data to fulfill the request. Upon completion, a raw string or a more complex *[[Response]]* object may be returned.
25 1 Elmer de Looff
26 1 Elmer de Looff
h3. TemplateParser (_View_)
27 1 Elmer de Looff
28 5 Elmer de Looff
Templates allow for a separation of presentation and logic, allowing you to move large parts of HTML or other output to a separate file. The *[[TemplateParser]]* replaces all the tags left in the template with the given output, which can be simple variables, or the use of multi-level database objects. Also, as an added benefit, the default output of TemplateParser is such that any text fed into the template, is automatically made safe for HTML output.
29 1 Elmer de Looff
30 1 Elmer de Looff
h3. Database abstraction (_Model_)
31 1 Elmer de Looff
32 5 Elmer de Looff
The *[[Model|µWeb database model]]* provides a Record class which provides for a smart interaction with your database tables. Creating a  simple Record subclass for each of your (main) database tables allows you:
33 1 Elmer de Looff
* to load database record by their primary key value;
34 1 Elmer de Looff
* automatic retrieval of 1-1 or n-1 relations;
35 1 Elmer de Looff
* creating, updating or deleting of records.
36 1 Elmer de Looff
37 1 Elmer de Looff
h3. HTTP Request abstraction
38 1 Elmer de Looff
39 5 Elmer de Looff
The *[[Request]]* class ensures that, no matter the server that accepts the request (Apache or BaseHTTPServer), the various parts further on in the framework have access to header information, query arguments, cookies and POST data in a structured manner. More information on the client, server and other environment variables is also available here.
40 1 Elmer de Looff
41 1 Elmer de Looff
h3. µWeb Standalone Server
42 1 Elmer de Looff
43 5 Elmer de Looff
*[[Standalone]]* is a module that allows µWeb to function outside the presence of Apache and mod_python. This is easy for local testing, or low volume websites.