Skip to content

Instantly share code, notes, and snippets.

@MahdiY
Created May 20, 2019 17:18
Show Gist options
  • Save MahdiY/8ca43a83e2229e58800db8485ed193f1 to your computer and use it in GitHub Desktop.
Save MahdiY/8ca43a83e2229e58800db8485ed193f1 to your computer and use it in GitHub Desktop.
Serve a directory with python
import http.server
import socketserver
import os
PORT = 786
web_dir = os.path.join(os.path.dirname(__file__), '<DIR>')
os.chdir(web_dir)
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print("Serving at port", PORT)
httpd.serve_forever()
@MahdiY
Copy link
Author

MahdiY commented May 20, 2019

Set your directory name instead of <DIR>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment