python - Firefox 中的 python cgi 问题

标签 python firefox forms cgi

我已经编写了一个 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 不知道如何打开此地址,因为协议(protocol) (c) 未与任何程序关联”。为什么会出现这个错误?它与我的 html 页面中的 cgi 脚本路径有关吗?提前致谢!

最佳答案

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

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

关于python - Firefox 中的 python cgi 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4707318/

相关文章:

php - 固化 "Back Button Blues"

Java spring 框架表单验证

python - 缩进错误 :at second char. lower()?

python - 遍历文件从列表中查找单词时的 findall() 正则表达式

Python:根据给定引用​​测量图像中的颗粒大小?

javascript - 用 Greasemonkey 替换 div 类中的 float

javascript - 有没有办法在 Firefox 扩展中对控件进行分组?

Python 3.4 不会从文本文件中读取超过一行

javascript - Firefox 扩展,访问文档

c# - (C#) 如何通过拖动和 "Open with ..."在我的程序中打开文件