import cgi
def fill():
s = """\
<html><body>
<form method="get" action="./show">
<p>Type a word: <input type="text" name="word">
<input type="submit" value="Submit"</p>
</form></body></html>
"""
return s
# Receive the Request object
def show(req):
# The getfirst() method returns the value of the first field with the
# name passed as the method argument
word = req.form.getfirst('word', '')
print "Creating a text file with the write() method."
text_file = open("/var/www/cgi-bin/input.txt", "w")
text_file.write(word)
text_file.close()
# Escape the user input to avoid script injection attacks
#word = cgi.escape(word)
test(0)
'''Input triggers the application to start its process'''
simplified_file=open("/var/www/cgi-bin/output.txt", "r").read()
s = """\
<html><body>
<p>The submitted word was "%s"</p>
<p><a href="./fill">Submit another word!</a></p>
</body></html>
"""
return s % simplified_file
def test(flag):
print flag
while flag!=1:
x=1
return
這個mod_python程序的fill方法發送文本來顯示方法,它將它寫入我的應用程序使用的input.txt文件中,直到我的應用程序正在運行爲止我不想讓其餘的語句工作,所以我有稱爲函數測試,其中我有一個while循環,它將持續循環直到標誌被設置爲1.如果它被設置爲1,那麼它將打破while循環並繼續執行其餘的語句。 我使我的應用程序通過測試標誌變量設置爲1.根據我的邏輯,它應該打破循環,並返回到顯示功能,並繼續執行休息,但它不以這種方式發生,其連續加載頁面!mod_python代碼錯誤!
請幫我度過這個..
謝謝.. :)
你真的需要再次考慮邏輯。正如答覆者指出的那樣,「測試」功能將會永遠運行,而不會返回。不管你從哪裏調用它,如果你不用'1'調用它,它永遠不會結束。 – 2011-05-14 21:16:32