Python/Web Server: Difference between revisions
From charlesreid1
(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() >>>...") |
No edit summary |
||
| Line 1: | Line 1: | ||
Notes on the Python | Notes on starting up the lightweight HTTP server built into Python. | ||
=Before you Begin= | =Before you Begin= | ||
Revision as of 19:39, 29 January 2016
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)