简体   繁体   English

刚开始使用Google App Engine并受到空白页的欢迎

[英]Just getting started on Google App Engine and being greeted with a blank page

I'm currently in Udacity's CS253 (Web Development) course, and I'm getting through the second homework project (the ROT13) website. 我目前正在参加Udacity的CS253(网络开发)课程,并且正在通过第二个家庭作业项目(ROT13)网站。 I paid attention to the lecture and I think I have a good grip on the code in the file naisho.py , which is here: 我关注了这次演讲,并且我对naisho.py文件中的代码有很好的掌握,该文件位于此处:

import webapp2
import codecs
import cgi

form = """
<form method="post">
    Tell me a secret...
    <br>
    <input type="text" name="secret" value="%(secret)s">

    <div style="color: red">%(error)s</div>

    <br>
    <br>

    <input type="submit">
</form>
"""

class MainPage(webapp2.RequestHandler):

    def process(s):
      return codecs.encode(s, "rot_13")

    def escape(s):
      return cgi.escape(s, quote = True)

    def write_form(self, error="", secret=""):
      self.response.out.write(form % {"error": error, 
                                      "secret": escape(secret)})

    def get(self):
        #self.response.headers['Content-Type'] = 'text/plain'
        self.write_form()

        #self.response.headers['Content-Type'] = 'text/plain'
        #self.response.write(self.request)

    def post(self):
        self.redirect('/thanks')

  class ThanksHandler(webapp2.RequestHandler):
    def get(self):
      n = process(secret)
      self.response.out.write(n)

    def escape(s):
      return cgi.escape(s, quote = True)

application = webapp2.WSGIApplication([
    ('/', MainPage), ('/thanks', ThanksHandler)], debug=True)

and file app.yaml provided: 和文件app.yaml提供:

application: naisho
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: naisho.application

I navigate to the folder in the terminal (I use OSX 10.9.3), enter dev_appserver.py --port=9999 . 我导航到终端中的文件夹(我使用OSX 10.9.3),输入dev_appserver.py --port=9999 . to load localhost:9999 , but get a blank page when I load it into my browser. 加载localhost:9999 ,但是当我将其加载到浏览器中时得到一个空白页。 I am absolutely puzzled as to why. 我绝对对为什么感到困惑。 Could someone point me in the right direction and also possibly point me in the direction of a reference to better diagnose these sorts of things? 有人可以指出我正确的方向,也可以指出我的参考方向以更好地诊断这类问题吗? Thank you folks kindly in advance. 提前谢谢大家。

First, your code contains some bugs and indentation problems. 首先,您的代码包含一些错误和缩进问题。

The bugs is that escape and process are methods of the class, so they should contain self as their first argument and be called as self.escape or self.process. 错误在于转义和处理是类的方法,因此它们应包含self作为其第一个参数,并称为self.escape或self.process。 An alternative would be to move those methods out of the class as functions. 一种替代方法是将这些方法作为函数移出类。

Once you do that, in the console you shouldn't see any error hidden in Stack Traces except for an annoying 303 error. 完成此操作后,在控制台中,除了令人讨厌的303错误之外,您应该不会在Stack Traces中看到任何隐藏的错误。

For whatever reason, I also get those 303 errors when running on the dev server, but if you deploy it to an App Engine instance, it works smoothly. 无论出于何种原因,在开发服务器上运行时,我也会收到303错误,但是如果将其部署到App Engine实例,它会顺利运行。

You could try to deploy to the App Engine first, and look into their logs to catch your bugs/indentation as it makes it easier to spot them. 您可以先尝试将其部署到App Engine,然后查看它们的日志以捕获您的错误/缩进,因为这样可以更轻松地发现它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM