【发布时间】:2017-08-30 21:31:28
【问题描述】:
我在 Windows 10 的 C:\Apache24\htdocs 目录下有两个文件 index.html 和 form.py。内容如下:
index.html
<html>
<head>
<title>demo web file python2.7</title>
</head>
<body>
<form name="pyform" method="POST" action="/form.py">
<input type="text" name="fname" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
form.py
#!C:\Python27/python
print "Content-Type: text/html"
import cgi,cgitb
cgitb.enable() #for debugging
form = cgi.FieldStorage()
name = form.getvalue('fname')
print "Name of the user is:",name
Apache 服务器配置为使用以下设置运行 cgi 脚本:
DocumentRoot "c:/Apache24/htdocs"
<Directory "c:/Apache24/htdocs">
Options Indexes FollowSymlinks ExecCGI
AllowOverride All
Require all granted
</Directory>
和
AddHandler cgi-script .cgi .py
当我填充文本区域并单击页面上的“提交”按钮时,我会在结果页面上获得 python 文件的全部内容,而不是我放入框中的内容。
缺少什么或我做错了什么?非常感谢。
【问题讨论】:
-
我在
print('Content-Type...之后缺少新行,但这与您的问题无关。 Apache 不接受form.py作为 CGI,因此不是 executing 而是显示文件的内容。