stupid simple web server with python Dec
08
1
0

If you need to set up a basic web server really fast and you don't want to go through the hassle of setting up nginx, apache or another production-level web server you can just use Python. If you're lucky like me you're already developing in it anyway.

Python comes with a simple web server built in: SimpleHTTPServer

All you need to do is to change to the directory you want to host and call it:

cd /path/to/directory
python -m SimpleHTTPServer

That's all there is to it. You'll then be serving rooted to that directory. You can access it through localhost, 127.0.0.1, or your inet IP.

It will look for and automatically host index.html. If index.html isn't found then it will list the contents of the directory specified.

http://localhost:8000
http://192.168.1.###:8000

The default port is 8000, but you can easily change it. One things I use this for is when I need to initiate more than one simple server at once.

python -m SimpleHTTPServer 8080

Keep in mind that this is a single threaded server and it breaks easily. This most definitely should NOT be used in production.

Among other things this an easy way to transfer files between computers through your local network using only Python.

reference: http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python

Bookmark and Share
blog comments powered by Disqus