1、python開啟http服務器
python -m SimpleHTTPServer 8080
如果提示錯誤:
python.exe: No module named SimpleHTTPServer
則試一下命令:
python -m http.server
2、執行py腳本文件,開啟cgi映射
python -m http.server --cgi 8000
py代碼里添加
header = 'Content-Type: text/html\n'
print(header)
比如/cgi-bin/1.py文件代碼:
header = 'Content-Type: text/html\n'
html = 'abc'
print(header)
print(html)
訪問http://127.0.0.1:8000/cgi-bin/1.py
可以正常輸出abc
Ps:
py代碼文件默認目錄在cgi-bin或者htbin
http.server官方文檔 https://docs.python.org/3/library/http.server.html