[Edu-sig] Writing a web server

Markus Gritsch gritsch@iue.tuwien.ac.at
Mon, 28 May 2001 10:59:46 +0200


Brent Burley and Pat Erb wrote:

> One of the things that is _really_ easy to do in Python is writing a web
> server.  In fact, the standard distribution comes with a fully functioning
> server as an example.  Find your lib directory and run SimpleHTTPServer.py
> directly and then open http://localhost:8000/ in your web browser.  This web
> server provides a simple server-side file browser that can navigate
> directories and serve up html, graphics, and text files.  This should work
> on most computers, including Windows, and you don't even need an Internet
> connection.  Try it!
>
> I've attached an even simpler web server (16 lines of code) that is the web
> equivalent of "hello world".  As simple as it is, it's complete enough that
> it shows everything you need to build a dynamic website.  Just send
> "text/html" instead of "text/plain" and generate an html file dynamically in
> the do_GET method.  The "self.path" variable contains the requested URL and
> can encode any information you want to pass between requests.
>
> How's this for a possible 9th/10th grade course:
> * Web Programming with Python - Students will program a fully-functioning
> website from scratch.  Students will choose from building an interactive
> storybook where the reader influences the outcome of the story, or a
> web-community site with a message board and voting booth.  No prior
> programming experience necessary.

If you want to show how a simple Webserver can be written, your approach is
fine.  If you want to concentrate on programming dynamic content for Webpages,
you could use
http://webware.sourceforge.net/
http://webware.sourceforge.net/Webware/Docs/

This package is a very promising approach to use Python for developing dynamic
served webpages without using ZOPE.  It also contains a
AsyncThreadedHTTPServer.py which makes it possible to use it without melting it
with Apache.

Enjoy, Markus