Python 3- 快速建立臨時網頁伺服器

於Python 2.x 可以快速的透過SimpleHTTPServer 模組建立一個臨時網站伺服器.但是使用Python 3 的時候,卻沒有SimpleHTTPServer 這個模組可以使用
原因是 “The SimpleHTTPServer module has been merged into http.server in Python 3.” SimpleHTTPServer 這個模組於Python 3 的時候被merge 到http.server
這個模組.所以在Python 3 要快速建立臨時網頁伺服器,方法如下

假設我們要分享 D:\website 的資料,先切換到該路徑,這邊以windows 下的python 為範例

cd /website

然後於該目錄輸入:

python -m http.server 8080

這樣就可以有個臨時的網頁伺服器了. 如果不想用8080 port 的話,可以自行定義8088 或其他的port

Tags: , , ,

Leave a Comment