Rich Dougherty

Quick Python web server on localhost

Python's SimpleHTTPServer is great for serving files from a directory without the hassle of setting us a proper web server.

$ python -m SimpleHTTPServer

But by default it listens on all network interfaces. If you only want to listen on localhost then you'll need to write a short script.

import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

SimpleHTTPRequestHandler.protocol_version = "HTTP/1.0"
httpd = BaseHTTPServer.HTTPServer(('', 8000), SimpleHTTPRequestHandler)

Adapted from an article at Linux Journal.