You Are Here: Home » Articles » How-To » Networks » Tech » Web

How to host a web server using Python ?

By Debjit on September 28th, 2009 
Advertisement

Hosting a web server using Python is very simple. Any default installation of Python includes a module called SimpleHTTPServer. We can make use of this module to start python and host a web server on any port as we wish. In this article we will show you how to do so.

Hosting a website quickly using python module

Hosting a website quickly using python module

1) Bring up a terminal and move to a directory which you want to be served.

2) Now type the following command in your terminal and hit enter

python -m SimpleHTTPServer port

3) You are done. point your web browser to your-ip:port. The contents of the directory from which you have started the python SimpleHTTPServer will be served as the default page. To Stop the webserver, you just need to hit Ctrl-C from the keyboard.

Check out this screencast and the screenshots for further details.

Permalink for the above screencast: http://blip.tv/file/1878275

This method of hosting a website is very dynamic. You can use this method to share any directory temporarily and yes on any port you like. You can also view real time access logs on the command line itself where you have started the python web server from.

View real time access logs for your python based webserver

View real time access logs for your python based webserver

Advertisement







How to host a web server using Python ? was originally published on Digitizor.com on March 17, 2009 - 7:32 am (Indian Standard Time)