开发者

Problem with python cgi in Firefox

I have written an html form and am trying to incorporate a python cgi script with it. I have already configured my apache server to execute cgi scripts from the cgi-bin directory. Here's the html form:

<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>

And here's the test2.py cgi script:

#!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>"

The html page is located in my htdocs folder and the cgi script is in the cgi-bin direct开发者_如何学运维ory. However, when I enter something into the form and submit, firefox returns an error message saying: "Firefox doesn't know how to open this address, because the protocol (c) isn't associated with any program". Why is this error occurring? Does it have something to do with my path to the cgi script in my html page? Thanks in advance!


You are correct: it has something to do with the path to the CGI script on the HTML page. The form's action attribute should refer to the path where the CGI script is getting interpreted on the server, e.g., /cgi-bin/test2.py.

Since you made this mistake, I'm assuming you are new to web development. Consider using mod_wsgi and a framework like Django instead of CGI, especially if you expect a lot of traffic or you are making a web application and not just handling a single form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜