I always use $ python -m SimpleHTTPServer
for fast local static web testing, it works great with index.htm
or index.html
as index files.
However I need to use default.htm
or default.html
for the project I'm working on at the moment. Can someone help to write a simple script for it please?
I found the below sample on the web, I hope it could help a little to get started.
import sys, SimpleHTTPServer, BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
SimpleHTTPRequestHandler.protocol_version = "HTTP/1.0"
httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], sa[1], "..."
httpd.serve_forever()
Here is one way:
Here is another way.
Finally, here is a package HTTP and HTTPS server, with various useful args. Run this with
-h
to see the help message.