0

我正在创建 HTML 表单并使用 Python 对其进行编码。我已经安装了 Apache 2.2 版和 Python 2.6 版。这是代码:

#!C:\Python26\Python.exe -u

#import cgi modules
import cgi

#create instances of field storage
form = cgi.FieldStorage()

#get data from the fields
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>"

我写的代码给了我一个内部错误。但是,当我删除以下行时,它运行良好。

#import cgi modules
    import cgi

    #create instances of field storage
    form = cgi.FieldStorage()

    #get data from the fields
    first_name = form.getvalue('first_name')
    last_name  = form.getvalue('last_name')

我编辑了 httpd 配置文件并添加了几行:

AddHandler cgi-script .cgi .py .pl

ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/"

为什么添加行时显示内部错误消息?而且,我是使用 Python 构建 HTML 表单的新手。关于使用 Python for Windows 的 HTML 表单教程的建议将非常有帮助。谢谢。

PS:包含脚本的文件位于 cgi-bin Apache 文件夹中。

4

1 回答 1

0

绝对有问题的是你减去了那些行,它仍然运行。print "<h2>Hello %s %s</h2>" % (first_name, last_name)在您的 HTML 正文中应该引发异常,因为它们尚未定义。

请为内部服务器错误发布您的 error.log 位。

于 2010-06-19T21:51:44.853 回答