0

我正在按照 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)
4

0 回答 0