使用python开发cgi

mini-httpd的配置文件里还是允许所有文件类型: cgipat=cgi-bin/**,建立下面的文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

import cgi

print "Content-type:text/htmlrnrn"
print "<html>"
print "<head><title> My first CGI </title></head>"
print "<body>"

print "<p> OK Done </p>"
print "</body>"
print "</html>"

form = cgi.FieldStorage()
if form.getvalue("name"):
print '<h2> Hello ' + form.getvalue("name") +" ! </h2> "

放到cgi-bin里,注意要有可执行权限,结果运行如下: