Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from BaseHTTPServer import HTTPServer
- from SimpleHTTPServer import SimpleHTTPRequestHandler
- class MyHandler(SimpleHTTPRequestHandler):
- def do_GET(self):
- # for my URIs, handle like this
- if self.path.startswith('/my/'):
- self.send_response(200)
- self.send_header('Content-type', 'text/html')
- self.end_headers()
- self.wfile.write('<html><head><title>Spam</title></head><body>Eggs</body></html>')
- # for all other URIs, use default handler
- else:
- SimpleHTTPRequestHandler.do_GET(self)
- httpd = HTTPServer(("", 8000), MyHandler)
- httpd.serve_forever()
- # now call:
- #
- # http://localhost:8000
- # http://localhost:8000/file.txt
- # http://localhost:8000/my/anything
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement