Skip to content

Instantly share code, notes, and snippets.

@nicolashery
Created September 21, 2012 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolashery/3761915 to your computer and use it in GitHub Desktop.
Save nicolashery/3761915 to your computer and use it in GitHub Desktop.
Python development web server for Windows

Python development web server for Windows

This is a simple Python script to serve static files from any project directory, useful when doing web development.

Usage

Simply put server.py and server.cmd in a directory, for instance C:\Users\YourName\bin and add that directory to your PATH.

Then in the console, cd to your project folder, type server and hit Enter (it will run on port 8000 by default, use server 5000 for example to change port). Use Ctrl+C to stop the server.

python "%~dp0\server.py" %*
#!/usr/bin/env python
import SimpleHTTPServer
map = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map
map[""] = "text/plain"
for key, value in map.items():
map[key] = value + ";charset=UTF-8"
try:
SimpleHTTPServer.test()
except KeyboardInterrupt:
print "Exiting..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment