Thursday, January 01, 2009

用几句Python做一个简单的web服务器

使用 一句python语句启动一个web server

python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
python -c "from SimpleHTTPServer import test;test()"
 
自定义端口启动一个web server
python -c "import SimpleHTTPServer;import SocketServer;PORT = 82;Handler = SimpleHTTPServer.SimpleHTTPRequestHandler;httpd = SocketServer.TCPServer(('', PORT), Handler);print 'serving at port', PORT;httpd.serve_forever()"


当然也可以自定义目录,请参考:
PYTHON 指定目录的WEB服务器

Tags: python, webserver