0
아래 코드에서 webapp2를 사용하여 udacity.com에서 웹 프로그래밍을 배우고 있습니다.이 코드는 연습 문제 중 하나입니다. 여기에서 달성하고자하는 것은 사용자가 양식을 렌더링하는 것입니다. 어떤 값을 입력 할 수 있습니다 제출 버튼을 누르면 사용자가 양식에 자신의 암호화 된 rot13 데이터를 볼 수 있어야합니다. 제출 버튼을 누르면 내 양식이 공백으로 표시되고 사용자 데이터가 손실되고 POST 메소드에서 self.request.get ("content")에 pdb를 사용하면 문제가 발생합니다. 비어있는 경우 올바른 방향으로 도움을 주시면 감사하겠습니다.webapp2에서 post 메서드를 사용할 수 없습니다.
import webapp2
import cgi
def escape_html(s):
return cgi.escape(s, quote = True)
form = """
<!DOCTYPE html>
<html>
<head>
<title>Unit 2 Rot 13</title>
</head>
<body>
<h2>Enter some text to ROT13:</h2>
<form method="post">
<textarea name="text" style="height: 100px; width: 400px; ">
%(content)s
</textarea>
<br>
<input type="submit">
</form>
</body>
</html>
"""
class MainPage(webapp2.RequestHandler):
def write_form(self, content = ""):
self.response.out.write(form %{"content": escape_html(content)
})
def get(self):
self.write_form()
def post(self):
content = self.request.get("content").encode("rot13")
self.write_form(content)
app = webapp2.WSGIApplication([('/', MainPage)],debug=True)