The SimpleHTTPServer module can be used in the following manner in order to set up a very basic web server serving files relative to the current directory.
1 2 3 4 5 6 7 8 9 10 11 |
import SimpleHTTPServer import SocketServer PORT = 8000 Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(("", PORT), Handler) print "serving at port", PORT httpd.serve_forever() |
The SimpleHTTPServer module can also be invoked directly using the -m switch of the interpreter with a port number argument. Similar to the previous example, this serves the files relative to the current directory.
1 |
python -m SimpleHTTPServer 8000 |