Minimal webserver in python

There is a minimal web server in the python standard library. To use it, change to the directory you want to serve and execute the script below:

[download simplewebserver.py]

#!/usr/bin/env python
 
import SimpleHTTPServer, BaseHTTPServer
 
try:
    BaseHTTPServer.test(SimpleHTTPServer.SimpleHTTPRequestHandler, 
                        BaseHTTPServer.HTTPServer)
except KeyboardInterrupt:
    print '^C received, bye bye!'

By default, the directory is served on port 8000, so point your browser to http://localhost:8000/ to see your freshly online website. Alternatively, you can specify the port as first argument. For example:

 > simplewebserver.py 1234

Posted by pierre on 8 September 2007 in python

Leave a Reply

*