示例一:bash开启
python -m http.server
# 指定开放路径
python -m http.server --directory /path/to/your/folder
示例二:python代码开启
from http.server import SimpleHTTPRequestHandler, HTTPServer
# 设置服务器地址和端口
host = 'localhost'
port = 8000
# 定义处理程序
handler = SimpleHTTPRequestHandler
# 创建服务器
with HTTPServer((host, port), handler) as server:
print(f"Server started at {host}:{port}")
# 启动服务器
server.serve_forever()