1、启用或者关闭windows功能,选择安装CGI。
2、安装后重新打开IIS看到CGI
3、配置ISAPI和CGI限制
4、右上角添加,路径是python安装路径,注意要加上两个 %s %s
点确定
5、处理映射关系
6、右上角 添加模块,模块选择:CgiModule
出现弹出框,点“是”
添加完成
7、接下来测试一下,创建一个网站
服务器端测试代码:
#!/usr/bin/python
import cgi
import json
#!/usr/bin/python
# print ("Content-Type: text/html")
# print ("")
# print ("<html>")
# print ("<h2>CGI Script Output</h2>")
# print ("<p>This page was generated by a Python CGI script.</p>")
# print ("</html>")
def main(): print ("Content-type: text/html\n")form = cgi.FieldStorage()print(form.keys())print(type(form))if form.keys() and form["ServiceCode"].value != "":print ("<h1> Hello",form["ServiceCode"].value,"</h1>" )else: print ("<h1> Error! Please enter first name.</h1>")
main()
访问测试URL: