Back to Top

Sunday, February 06, 2011

How to quickly start up a webserver with Python

SONY DSC Sometimes you need to quickly start up a webserver that serves up static files (I will describe such a case in the next post). Python to the rescue (works on both Linux and Windows if you have Python installed):

For Python 2.x (this is what most sites show you):

python -m SimpleHTTPServer 9914

For Python 3.x (thanks to this comment):

python -m http.server 9914

These will start up a webserver on port 9914, and you can access it via the address http://localhost:9914. Warning! The webserver will be available to anyone who can connect to your computer directly (unless there are other mechanisms to restrict it – like firewalls or NAT), so use your judgment!

Picture taken from bob's photostream with permission.


Post a Comment

You can use some HTML tags, such as <b>, <i>, <a>. Comments are moderated, so there will be a delay until the comment appears. However if you comment, I follow.