python开启http服务

官方文档例子。 

import http.server
import socketserver

port=8000
handl=http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(('127.0.0.1',port),handl) as httpd:
    print('sering st port',port)
    httpd.serve_forever()

如图,如果里面有index.html,会直接显示index.html页面

猜你喜欢

转载自my.oschina.net/oisanblog/blog/1805407