From charlesreid1

Notes on starting up the lightweight HTTP server built into Python.

Before you Begin

Start by figuring out where you are at and listing the contents of the directory:

>>> import os
>>> os.getcwd()
>>> os.listdir()

If you need to go to a different directory,

>>> os.chdir('some_directory/')


Python 2

From Command Line

Run Python's lightweight HTTP server straight from the command line:

$ python -m SimpleHTTPServer 8008

to serve files in Python's current working directory on port 8008. Access it by going to localhost:8008 in a browser on the same machine.


Python 3

From Command Line

python3 -m simple.http

From a Script

import http.server
http.server.test(HandlerClass=http.server.SimpleHTTPRequestHandler,port=80)

Writing Your Own Handler

See this page: http://sheep.art.pl/Wiki%20Engine%20in%20Python%20from%20Scratch