Skip to content
Advertisement

How to run a http server which serves a specific path?

this is my Python3 project hiearchy:

JavaScript

From script.py, I would like to run a http server which serve the content of the web folder.

Here is suggested this code to run a simple http server:

JavaScript

but this actually serve project, not web. How can I specify the path of the folder I want to serve?

Advertisement

Answer

In Python 3.7 SimpleHTTPRequestHandler can take a directory argument:

JavaScript

and from the command line:

JavaScript

To get a little crazy… you could make handlers for arbitrary directories:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement