Udacity.com のチュートリアルに従って Web 開発を学んでおり、現在 Google App Engine で rot13 アプリを作成する必要があります。
エラーの原因はPOST function
. コメントアウトすると、何もできなくてもアプリを見ることができます。
しかし、コメントを外すと、ブラウザに空白のページが表示されます。
ここで私が間違っていることについてのいくつかの指針を得ることを望んでいます。前もって感謝します
import webapp2
import cgi
form="""<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;"> </textarea>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
"""
def rot13(a):
list1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
list2 = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
result = ''
for e in a:
if e in list1:
result = result + list2[list1.find(e)]
else:
result = result + e
return result
def escape_html(s):
return cgi.escape(s, quote = True)
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
def post(self):
rot13 = ''
text = self.request.get('text')
if text:
rot13 = text.encode('rot13')
self.response.out.write(form, text = rot13)
application = webapp2.WSGIApplication([('/', MainPage)], debug=True)