Local Web Server With Python

Need a quick and easy server on your local computer? Look no further than Python’s SimpleHTTPServer. You can run a quick command and have a functioning web server to serve files that your browser can read.

In your shell you can run:

# Python 3
python3 -m http.server

# Python 2
python -m SimpleHTTPServer

After running, you’ll see the following:

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/)

If you then open up your browser at that address you’ll be able to see the output of your local server. So let’s say you have a file called index.html in a folder that has some content, “Hello World” for example. You then navigate to your terminal and from the directory that index.html is in you run python -m SimpleHTTPServer

Navigating to http://localhost:8000 or http://0.0.0.0:8000/ will show you the contents of index.html so you’ll see “Hello World” from your browser.

Read more about it Python’s simple web server.

Instagram Post