标签:
1.页面请求 form形式 ,get方法请求
http://localhost/cgi-bin/form.py 获得表单,输入内容提交,得到response
----
form.py
#!C:/python27/python.exe # -*- coding: UTF-8 -*- print "Content-type:text/html\r\n\r\n" print "<html>" print "<head>" print "<title>Hello - Second CGI Program</title>" print "</head>" print "<body>" print ‘‘‘<p> <form action="/cgi-bin/hello_get.py" method="get"> First Name: <input type="text" name="first_name"> <br /> Last Name: <input type="text" name="last_name" /> <input type="submit" value="Submit" /> </form> </p>‘‘‘ print "</body>" print "</html>"
hello_get.py
#!C:/python27/python.exe # -*- coding: UTF-8 -*- import cgi, cgitb form = cgi.FieldStorage() first_name = form.getvalue(‘first_name‘) last_name = form.getvalue(‘last_name‘) print "Content-type:text/html\r\n\r\n" print "<html>" print "<head>" print "<title>Hello - Second CGI Program</title>" print "</head>" print "<body>" print "<h2>Hello %s %s</h2>" % (first_name, last_name) print "</body>" print "</html>"
2.页面请求 form形式 ,post方法请求
form-post.py
form-post.py hello_get.py 也可以处理post
#!C:/python27/python.exe # -*- coding: UTF-8 -*- print "Content-type:text/html\r\n\r\n" print "<html>" print "<head>" print "<title>Hello - Second CGI Program</title>" print "</head>" print "<body>" print ‘‘‘<p> <form action="/cgi-bin/hello_get.py" method="post"> First Name: <input type="text" name="first_name"> <br /> Last Name: <input type="text" name="last_name" /> <input type="submit" value="Submit" /> </form> </p>‘‘‘ print "</body>" print "</html>"
标签:
原文地址:http://www.cnblogs.com/Citizen/p/4789518.html