首页 > 代码库 > python快速搭建WebServer

python快速搭建WebServer

#!/usr/bin/pythonimport SimpleHTTPServerimport SocketServerimport osPORT = 7777WEBDIR = "/www/web/xxx_com/"class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):    def translate_path(self, path):        os.chdir(WEBDIR)        return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self,path)try:    httpd = SocketServer.TCPServer(("", PORT), Handler)    print "dir %s serving at port %s"%(repr(WEBDIR), PORT)    httpd.serve_forever()except:pass

 

python快速搭建WebServer