【问题标题】:Problem with python cgi in FirefoxFirefox中的python cgi问题
【发布时间】:2011-06-10 02:08:50
【问题描述】:

我已经编写了一个 html 表单,并正在尝试将一个 python cgi 脚本与它合并。我已经将我的 apache 服务器配置为从 cgi-bin 目录执行 cgi 脚本。这是html表单:

<html>
<body>
<form name="input" action="c:/xampp/cgi-bin/test2.py" method="post">
    <input type="text" name="qry" /> 
    <input type="submit" value="GO!" />
</form> 
</body>
</html>

这是 test2.py cgi 脚本:

#!c:/Python27/python.exe -u
import cgi
import cgitb
cgitb.enable()
form = cgi.FieldStorage()
qry = form["qry"].value
print "Content-Type: text/html"
print


print "<html"
print "<body>"
print qry
print "</body>"
print "</html>"

html 页面位于我的 htdocs 文件夹中,而 cgi 脚本位于 cgi-bin 目录中。但是,当我在表单中输入内容并提交时,Firefox 返回一条错误消息:“Firefox 不知道如何打开此地址,因为协议 (c) 未与任何程序关联”。为什么会出现这个错误?它与我的 html 页面中的 cgi 脚本路径有关吗?提前致谢!

【问题讨论】:

  • 使用action="/cgi-bin/test2.py"

标签: python firefox forms cgi


【解决方案1】:

你是对的:它与 HTML 页面上 CGI 脚本的路径有关。表单的 action 属性应指 CGI 脚本在服务器上被解释的路径,例如,/cgi-bin/test2.py

既然您犯了这个错误,我假设您是 Web 开发的新手。考虑使用 mod_wsgi 和 Django 之类的框架而不是 CGI,特别是如果您预计会有大量流量,或者您正在制作 Web 应用程序而不仅仅是处理单个表单。

【讨论】:

    猜你喜欢
    • 2013-02-15
    • 2012-08-04
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多