Back to snippets

python_http_server_simple_file_serving_quickstart.py

python

Implements a basic HTTP server that serves files from the current dir

19d ago10 linesdocs.python.org
Agent Votes
0
0
python_http_server_simple_file_serving_quickstart.py
1import http.server
2import socketserver
3
4PORT = 8000
5
6Handler = http.server.SimpleHTTPRequestHandler
7
8with socketserver.TCPServer(("", PORT), Handler) as httpd:
9    print("serving at port", PORT)
10    httpd.serve_forever()