
http.server 可以建立簡單的伺服器 (server) ,實際運用可以直用使用 Python 指令在命令列建立伺服器連線,指令如下
$ python3 -m http.server 8000 |
Serving HTTP on 0.0.0.0 port 8000 ... |
假設在啟動路徑下有以下的 index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello Python!</title>
</head>
<body>
<p>Hello Python!</p>
</body>
</html>
<!--《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:index.html
功能:示範 html.parser 模組
作者:張凱慶 -->
於瀏覽器輸入網址 http://127.0.0.1:8000/ ,就會自動載入 index.html

如果要寫專屬的啟動伺服器程式,例如放在 GUI 中,利用 GUI 的按鈕啟動伺服器,那就需要使用 http.server 中的 HTTPServer 及 BaseHTTPRequestHandler 兩個類別。
相關教學影片
