我正在学习如何通过CGI发送数据。我有一个基本表单,我通过CGI提交一个字段 名称:
以及接收该字段并显示它的python脚本
#!F:/Python/python.exe
import cgi
form = cgi.FieldStorage() # instantiate only once!
name = form.getfirst('name', 'empty')
# Avoid script injection escaping the user input
name = cgi.escape(name)
print """\
Content-Type: text/html\n
<html><body>
<p>The submitted name was "%s"</p>
</body></html>
""" % name
我的主要问题是两个文件之间的链接不起作用。一旦我验证我的表单没有执行python脚本,但是我的代码写在里面的页面。 另一方面,如果我直接过去这个网址“http://localhost/cgi-bin/process_form.py?name=Joe”,它的工作没有任何问题。 你对我的错误的起源有所了解吗? 谢谢你的帮助
答案 0 :(得分:0)
您的网络服务器被认为是解释cgi-bin中的python文件的方式。检查您的Web服务器配置并将其更改为所需的目录。
以下是Apache和Nginx的一些链接: