简体   繁体   English

通过HTML表单运行时,Python CGI脚本未执行

[英]Python CGI script not executing when run through HTML form

I am trying to experiment with python's cgi module, ad do't want to buy an entire server just to accomplish this task. 我正在尝试使用python的cgi模块进行试验,广告并不想为了完成此任务而购买整个服务器。 So I have written my html and python cgi script on my Ubuntu 14.04 computer, but the script will not run. 因此,我已在Ubuntu 14.04计算机上编写了html和python cgi脚本,但是该脚本无法运行。 Here is the relevant HTML code: 以下是相关的HTML代码:

<form action = "cgi-bin/Login.py" method="get">

    Username <input type = "text" name = "user"><br>

    Password: <input type = "password" name = "password"><br>

    <input type = "submit" value = "Submit"><br>

</form>

And the Python 3 Code 还有Python 3代码

import cgi, cgitb

form = cgi.FieldStorage()



# Get data from fields
Username = form.getvalue('user')
Password  = form.getvalue('password')


print ("Content-type:text/html")
print ()
print ("<html>")
print ("<head>")
print ("<title>Hello - Second CGI Program</title>")
print ("</head>")
print ("<body>")
print ("<h2>Hello %s %s</h2>" % (Username, Password))
print ("</body>")
print ("</html>")

And lastly the popup that I get when I click the submit button on the webpage. 最后,当我单击网页上的“提交”按钮时出现的弹出窗口。

在此处输入图片说明

You'll need to setup and configure a web server to serve the cgi scripts. 您需要设置和配置Web服务器以提供cgi脚本。 Here's the apache documentation on that. 这是有关此文件的apache文档。

Try use POST in the form. 尝试使用POST形式。 CGI on python needs POST to works. python上的CGI需要POST才能起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM