编写一个server.py文件
1 import http.server 2 import socketserver 3 4 PORT = 8000 5 6 Handler = http.server.SimpleHTTPRequestHandler 7 8 with socketserver.TCPServer(("",PORT), Handler) as httpd: 9 print("Server started at localhost:" + str(PORT)) 10 print("http://localhost:"+ str(PORT)+"/") 11 httpd.serve_forever()
同级目录下创建一个index.html
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 我是一个静态文件 9 </body> 10 </html>
管理员身份运行server.py,
要不然会报错存储被拒 PermissionError: [WinError 5] 存取被拒。
python server.py
网页输入:http://localhost:8000/
标签:web,http,19,py,server,python,PORT,localhost From: https://www.cnblogs.com/mxx520/p/17848749.html