独书先生 Menu

python开启本地Web服务器

<img class="wp-image-373 size-full" src="https://dushusir.com/wp-content/uploads/2018/06/python_web_server.png" alt="python_web_server" width="600" height="300" /> python_web_server

1.安装python3.6

  1. 在相应文件目录地址栏敲击cmd

3.输入:python -m http.server

4.保证本地目录包含index.html之类的首页文件,谷歌浏览器地址栏输入:http://localhost:8000/即可访问

 

注意:(1)默认端口 8000,如果想要自定义端口如2333,使用 python -m http.server 2333

(2)如果电脑里已有python 2.X版本,而你运行的也是python 2.X版本, 则需要使用 命令:
python -m SimpleHTTPServer
(3) 如果提示: ”python” 不是内部或外部命令,也不是可运行的程序
或批处理文件,则按下列步骤操作:

[1]使用系统目录方式进入cmd(win+R==>cmd)

[2]输入python 确认环境变量已配置,未配置的去配置Python环境变量

[3]cd到当前目录下(如:cd /d D:\Code)

[4]重新输入python -m http.server即可