httpserver - How to serve a folder at a specific context using Python's SimpleHTTPServer -


i want serve contents of folder on different context.

example: have folder called "original" index.html in on windows box. if cd folder type in this,

 python -m simplehttpserver 

now can access index.html http://127.0.0.1:8000/index.html

how can write custom python script can serve same index.html file @ http://127.0.0.1:8000/context/index.html

sth this, need parse request path parts if need more refined approach (adapted test python server, use needed):

# simple custom http server class testhandler(http.server.simplehttprequesthandler):      def do_get(self):         # if main path requested         # load template , output         if  self.path == "/" or self.path == "":             out = contemplate.tpl('main', main_template_data)             self.send_response(200)             self.send_header("content-type", "text/html")             self.send_header("content-length", str(len(out)))             self.end_headers()             self.wfile.write(bytes(out, 'utf-8'))             return         # else default behavior other requests         return http.server.simplehttprequesthandler.do_get(self)   # start server httpd = socketserver.tcpserver((ip, port), testhandler) print("application started on http://%s:%d" % (ip, port)) httpd.serve_forever() 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -