此处默认配置好python3环境并默认使用pycharm进行开发
参考地址:http.server
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
将以上代码保存为server.py 保存影响即可,
运行成功会输出 serving at port 8000 即服务在8000端口运行
在同一目录创建index.html
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>毕业生读书报告</title>
</head>
<body>
Hello Word
</body>
</html>
此时就可以通过在浏览器输入 http://127.0.0.1:8000/index.html 进行访问