import cgi #倒入cgi模块
print 'Content-Type: text/html' #必须,输出HTML文档头 print # Blank line marking end of HTTP headers #必须,文档头必须以空行结束
cgiParameters = cgi.FieldStorage() #取得Post或Get过来的参数集
# 检查看是否是我们需要的参数 if not (cgiParameters.has_key("name") and cgiParameters.has_key("address")):#如果不是输出form,要求填写name和address print "<form action='' method='post' name='form'><input name='name' id='name'><input name='address' id='address'><input type='submit' value='submit'></form>" print "Please fill in the name and address fields." else: #如果是我们要求的参数,输出参数内容 print "<p>name:", cgiParameters["name"].value print "<p>address:", cgiParameters["address"].value |