1.在 电脑 某盘 的根目录 创建 www/cgi-bin 文件夹 将自定义的.py文件放到里面
例如:创建hello.py 内容如下:
#!/usr/bin/python3
print ("Content-type:text/html")
print () # 空行,告诉服务器结束头部
print ('<html>')
print ('<head>')
print ('<meta charset="utf-8">')
print ('<title>Hello Word - 我的第一个 CGI 程序!</title>')
print ('</head>')
print ('<body>')
print ('<h2>Hello Word! 我是来自菜鸟教程的第一CGI程序</h2>')
print ('</body>')
print ('</html>
2 .管理员启动 cmd命令提示符
到www文件下 ,启动http服务器
命令:python -m http.server --cgi (linux 环境不用带 --cgi)
3. 访问 http://localhost:8000/cgi-bin/hello.py