Created
February 21, 2012 06:25
-
-
Save hostage/1874226 to your computer and use it in GitHub Desktop.
Simple python snippet to serve files via http from the current folder. Automatically opens a browser pointed at the root url as a convenience.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Launch an http server on localhost using a random port to serve files from | |
# the current working folder. Automatically open a web browser pointed at the | |
# root url as a convenience. | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
from BaseHTTPServer import HTTPServer | |
import webbrowser | |
# Create a localhost server, specify port 0 so it will pick one for us. | |
httpd = HTTPServer(("localhost", 0), SimpleHTTPRequestHandler) | |
print "Server started on port: " + str(httpd.server_port) | |
# Open the browser; if index.html exists it will be opened, otherwise the user | |
# will get a directory listing. | |
webbrowser.open_new_tab("http://localhost:" + str(httpd.server_port)) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment