===== CGI 程序=====
#!/usr/local/bin/python
import cgi
def main():
print "Content-type: text/html\n"
form = cgi.FieldStorage() # parse query
if form.has_key("firstname") and form["firstname"].value != "":
print "Hello", form["firstname"].value, "
"
else:
print "Error! Please enter first name.
"
main()
===== .htaccess 设置 =====
如果你是用bluehost/dreamhost之类的共享空间,你需要修改你的.htaccess文件,让Apache能够识别py文件为CGI脚本程序。
AddType text/html py
AddHandler cgi-script .py