Operation Manual

Human-computer interfacing
121
Notes:
Inputs
The main input to a web application is in the form of a “page request” from a web
browser. As part of this request, variables are passed from the web browser to the
web server (in this case, your program). These variables might include things such
as the specific page you want to see, login details, details about how you would
like the site to look and so on.
Normally, these variables exist only for the lifetime of one request. Once you close
your browser, they’re gone, and if you visit the site again, you’ll have to specify the
details of your request to the server all over again. If you want variables that
persist between requests, you can use a special type of variable called a “cookie”.
Cookies are stored by the web browser and remembered between requests.
Your application’s inputs can be more than just page requests from a web browser
though – a database is often used to store data, for example. You could even use
the temperature of the room from a thermometer connected to your Raspberry Pi!
Outputs
Outputs from a web application are called a “response. The output is normally
in the form of the HTML of a web page, although it could be any data type, such
as a JPG file (a picture). The content of this output is generated by the web
application. You could even make your application produce a completely different
type of output as well as a web page – for example, changing the message on a
large electronic sign connected to your Raspberry Pi.
Processing
On the following pages are two simple Python programs that run as web servers.
This code will also run without modification on a commercial web server running
Apache web server software and the mod_wsgi Python module.
To complete this exercise, you will need to download and install the “WebOb 1.2”
Python module. You’ll find this either on the Raspberry Pi SD card or at the web
address http://pypi.python.org/pypi/WebOb/