From charlesreid1

Revision as of 19:39, 29 January 2016 by Admin (talk | contribs) (Created page with "Notes on the Python web server. =Before you Begin= Start by figuring out where you are at and listing the contents of the directory: <pre> >>> import os >>> os.getcwd() >>>...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Notes on the Python web server.

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)