我已經創建了一個帶有表單的HTML頁面,它接受一個名稱和密碼,並將它傳遞給一個Python腳本,該腳本應該用歡迎信息打印人員名稱。但是,在POST值後,我只是得到了瀏覽器中顯示的Python代碼,而不是歡迎消息。我已將html文件和python文件存儲在Apache 2.2下的cgi-bin文件夾中。如果我只是在瀏覽器中運行一個簡單的hello world python腳本,就會顯示「Hello World」消息。我使用WinXP,Python 2.5,Apache 2.2。我想要運行的代碼如下:HTML表單不能與python合作
#!c:\python25\python.exe
import cgi
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
reshtml = """Content-Type: text/html\n
<html>
<head><title>Security Precaution</title></head>
<body>
"""
print reshtml
User = form['UserName'].value
Pass = form['PassWord'].value
if User == 'Gold' and Pass == 'finger':
print '<big><big>Welcome'
print 'mr. Goldfinger !</big></big><br>'
print '<br>'
else:
print 'Sorry, incorrect user name or password'
print '</body>'
print '</html>'
這個問題的答案可能是非常明顯的,但它完全逃避我。我對Python很陌生,所以任何幫助將不勝感激。
謝謝。
爲什麼不使用mod_wsgi或正確的web框架? – 2009-08-21 10:37:41