Quickly serve a folder via Web Server
Sometimes you'll want to quickly serve a folder from the commandline, so you can view the contents in the browser. For example, if you're generating a static website or want to view how animated GIFs or SVGs appear in the browser.
Python comes with a mini web server included, which you can use to serve any folder. In this short tutorial we'll step through the process for serving a folder, as well as customizing the port on which the files are served.
Start the server
cd to the directory you want to serve.
Python 3
At the shell prompt enter python -m http.server
Python 2.7
At the shell prompt enter python -m SimpleHTTPServer
Access the files from your browser
When run the command will output the address & port that the server is available on.
martin@WINDOWS-GQV139L www $ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...localhost.Open your web browser and access http://localhost:PORT/
You can optionally provide a port number e.g. python -m http.server 8080 Â to set the port yourself. You can only serve a single folder at each port. If you set the port number yourself remember to change the port used in when accessing in the browser.
For example, using python -m http.server 8080 we would access the served folder through with http://localhost:8080