Using Python's simple HTTP server

John John (304)
5 minutes

I started programming in PHP, so by default I would use apache even when I just wanted to test basic HTML files. As I was learning Python, I discovered a great HTTP request handler. I often need to build a quick demo in JavaScript and HTML and Python's SimpleHTTPServer has come in quite handy.


Howchoo is reader-supported. As an Amazon Associate, we may earn a small affiliate commission at no cost to you when you buy through our links.

You will want to invoke the HTTP server from the directory you consider to be the document root. Supposing your project folder is /home/tyler/project1 you can change directories like this:

cd /home/tyler/project1

If your project is in your home directory you could also use this command:

cd ~/project1

You can invoke the simple HTTP server with the -m flag like this:

python -m SimpleHTTPServer

This will automatically use your current directory as the document root. It will server files in the current directory and below. It directly maps the HTTP requests to the directory structure.

When you start the server you should see something like this:

Serving HTTP on port 8000 ...

By default, this command will start the HTTP server on port 8000 and bind to any available IP (signified by In most cases, you'll be able to make requests to http://localhost:8000 in order to use the server.

If you want to use a port other than 8000, you can do so by specifying the port at the end of the same command:

python -m SimpleHTTPServer 8080

Keep in mind that if you specify a port lower than 1024 (like port 80), you will have to use root:

sudo python -m SimpleHTTPServer 80

You can visit your site in a web browser by typing the following in the url bar:

Zach Zach (248)
10 minutes

By default, the HTML exported from Google Docs includes tons of classes, styles, and is generally messy. This short guide will teach you how to export clean HTML devoid of classes and inline styles.