Python3搭建本地web服务器

Python3搭建本地web服务器

终端输入:

python3 -m http.server 3000

会在本地建立一个服务器。起始目录为 当时终端所在目录

  • -m module-name
  • http.server python模块- HTTP服务器
  • 3000 端口确定,可以为其他

根据上面命令,浏览器输入 localhost:3000/ 即可访问


设置其他的绑定的特定地址

版本3.4中的新增功能

python3 -m http.server 8000 --bind 127.0.0.1
  • -b/–bind 指定应绑定的特定地址

设置指定目录

版本3.7中的新增功能

python -m http.server --directory /tmp/
  • -d/–directory 指定应为其提供文件的目录

猜你喜欢

转载自blog.csdn.net/qq_31766287/article/details/81505209