import os
from http.server import HTTPServer,CGIHTTPRequestHandler
webdir = '.' # 设置网站的根目录为程序所在路径
port = 8080 # 设置一个端口
os.chdir(webdir)
server_address = ('',port) # 设置服务器地址
server_obj = HTTPServer(server_address,CGIHTTPRequestHandler) # 创建服务器对象
server_obj.serve_forever() # 启动服务器
----------------------------------------------
访问服务器 http://127.0.0.1:8080
----------------------------------------------
原文链接:https://blog.csdn.net/FHGFHFYUUGY/article/details/104537483