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 파일에 기록하는 메소드를 보여주기 위해 텍스트를 전송합니다. 나머지 문장은 작동하지 않기를 원합니다. 함수 테스트는 플래그가 1로 설정 될 때까지 반복적으로 반복되는 while 루프를가집니다. 1로 설정된 경우 while 루프를 중단하고 나머지 명령문을 계속 실행합니다. 내 로직에 따라 테스트 플래그 변수를 전달하기 위해 응용 프로그램을 만들었습니다. 루프를 중단하고 함수를 표시하고 나머지를 계속 실행해야하지만 그 방법으로는 일어나지 않습니다. 지속적으로 페이지가로드됩니다! mod_python 코드의 오류!
이를 통해 저를 도와주세요 .. 감사합니다 .. :)
논리에 대해 다시 생각해 볼 필요가 있습니다. 응답자가 지적했듯이,'test' 함수는 단순히 영원히 돌아가서 돌아 가지 않을 것입니다. 당신이 그것을 어디에서 부르든 상관 없습니다. 만약 당신이 그것을 '1'로 부르지 않는다면 결코 끝나지 않을 것입니다. –