2012-12-05 50 views
0

我正在學習Python的,,所以我得到了這個運動從一本書: 這是一個html形式:蟒蛇在線形式(例如反饋)不能正常工作

<html> 
    <body> 
    <form method=POST action="cgi-bin/cgi101.py"> 
     <P><b>Enter your name:</b> 
     <P><input type="text name=user" /> 
     <P><input type="submit" /> 
    </form> 
    </body> 
</html> 

這是腳本調用:

#!/usr/bin/python3 
import cgi 
form = cgi.FieldStorage() 
# parse form data 
print('Content-type: text/html\n') 
# hdr plus blank line 
print('<title>Reply Page</title>') 
# html reply page 
if not 'user' in form: 
    print('<h1>Who are you?</h1>') 
else: 
    print('<h1>Hello <i>%s</i>!</h1>' % cgi.escape(form['user'].value)) 

通過,如果我輸入用戶的邏輯,必須打印

你好用戶

。但它給了

你是誰?改爲

。這意味着腳本不會在表單中看到用戶。爲什麼? cgi/py腳本允許在apache中用於cgi-bin /。

回答

1

您在這裏有一個錯字:

<input type="text name=user" /> 

這實際上應該是這樣的:

<input type="text" name="user" /> 

類型和名稱都在輸入HTML標籤中的每個屬性。他們將永遠在的形式是:

<sometag attribute1="a thing" attribute2="another thing" /> 

請注意引號和等號的位置。語法突出顯示的優秀文本編輯器將幫助您的眼球更清楚地看到這一點。

+0

史詩般的失敗......感冒後我不應再編碼......謝謝! – boldnik