簡體   English   中英

通過HTML表單運行時,Python CGI腳本未執行

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

我正在嘗試使用python的cgi模塊進行試驗,廣告並不想為了完成此任務而購買整個服務器。 因此,我已在Ubuntu 14.04計算機上編寫了html和python cgi腳本,但是該腳本無法運行。 以下是相關的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>

還有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>")

最后,當我單擊網頁上的“提交”按鈕時出現的彈出窗口。

在此處輸入圖片說明

您需要設置和配置Web服務器以提供cgi腳本。 這是有關此文件的apache文檔。

嘗試使用POST形式。 python上的CGI需要POST才能起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM