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: