You can create an HTTP server in python using the http.server module.
Starting server from the command line
To start a server from a command line, navigate to your projects directory
Then start an HTTP server using the following command:
By default, this will run the contents of the directory on a local web server, on port 8000. You can go to this server by going to the URL localhost:8000 in your web browser.
Starting server programmatically
To start an HTTP server from within the python script, you can use socketerserver along with http.server. The SimpleHTTPRequestHandler class can be used in the following manner in order to create a very basic webserver serving files relative to the current directory:
This will run the contents of the directory on a local web server, on port 8000. You can go to this server by going to the URL localhost:8000 in your web browser.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.