1. 程式人生 > >Python3搭建本地web伺服器

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 指定應為其提供檔案的目錄