this is my Python3 project hiearchy:
projet
\
script.py
web
\
index.html
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:
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()
but this actually serve project
, not web
. How can I specify the path of the folder I want to serve?
python3 -m http.server -d /path/to/web/dir
on command line to do the job? Props to @kyle-barron who gave this perfect solution in a comment deep below. – Unreasonserver.py: error: argument port: invalid int value: '/media/EHD/web_root'
error when I run that in Ubuntu 18.04 Terminal (with python3.6.9) – Maurits