跳至内容
Python 俱乐部
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
python-network-application:cgi
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== Python CGI 编程 | 类FieldStorage的使用====== 使用Python自带的cgi库,可以很容易的实现CGI编程。\\ 下面的例子实现了使用 类FieldStorage 得到POST或GET参数的方法 ===== 表单示例 ===== <code html> <form method="POST" action="http://host.com/cgi-bin/test.py"> <p>Your first name: <input type="text" name="firstname"> <p>Your last name: <input type="text" name="lastname"> <p>Click here to submit form: <input type="submit" value="Yeah!"> <input type="hidden" name="session" value="1f9a2"> </form> </code> ===== CGI 程序===== <code python> #!/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 "<h1>Hello", form["firstname"].value, "</h1>" else: print "<h1>Error! Please enter first name.</h1>" main() </code> ===== .htaccess 设置 ===== 如果你是用bluehost/dreamhost之类的共享空间,你需要修改你的.htaccess文件,让Apache能够识别py文件为CGI脚本程序。 <code> AddType text/html py AddHandler cgi-script .py </code>
python-network-application/cgi.txt
· 最后更改: 2011/01/21 01:44 (外部编辑)
页面工具
显示页面
修订记录
反向链接
回到顶部