5. Examples

As you read through the Module Reference section of the documentation you will come across a number of examples. All the exmples from the Module Reference can be found in the doc/src/lib directory of the distribution.

The examples with a filename starting with command- are designed to be run from the command line. Those starting with webserver- are designed to be run by the test webserver. If you are using the test webserver you do not need to install the modules to test the examples. They will run directly from the source distribution.

The web modules distribution comes with a simple Python webserver, similar to the one described earlier in this document. The test webserver is designed to allow you to test the examples in this documentation on your own machine. To use it run the webserver.py file in the scripts directory of the source distribution. If you run the webserver and visit http://localhost:8080/doc/html/web/examples.html on your local machine you should see the examples index page. If this is the case you can test the examples on your own computer.

Warning: For the webserver to work properly, the path to the webserver.py file should contain no spaces. One important point to note about the test webserver is that it treats all paths relative to the place where the webserver is running and not relative to the script it is executing. This means that if you want to run the examples on a different webserver you will have to change the paths to certain files.

Please note the first line in each of the examples is the following:

#!/usr/bin/env python

You should change this line to whatever you use on your system to run Python. This doesn't apply if you are running Windows but on UNIX systems you may need to change it. Common values are:

#!/usr/bin/python

or

#!/usr/local/bin/python

and there should be two blank lines after this line.

The examples use UNIX linefeeds. This means that if you use something like notepad.exe on Windows all the lines will look like they run into one. Instead use IDLE (included with Python) or WordPad to display the examples correctly.

Below is an index of examples from the module reference:

web.auth
web.database
web.database.object
web.environment
web.error
web.form
web.image.graph
web.mail
web.session
web.template
web.util
web.wsgi