简体   繁体   中英

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. So I have written my html and python cgi script on my Ubuntu 14.04 computer, but the script will not run. Here is the relevant HTML code:

<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

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. Here's the apache documentation on that.

Try use POST in the form. CGI on python needs POST to works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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