简体   繁体   English

Google App Engine:POST请求后为空白页

[英]Google App Engine: Blank page after POST request

When I click on the "Add" button in my web application, this address shows up: 当我在Web应用程序中单击“添加”按钮时,此地址显示:

localhost:8080/add 本地主机:8080 /添加

but with a blank page. 但页面空白。

main.py: main.py:

class Add(webapp2.RequestHandler):
    def post(self):
        print("Test")
        ...
        return self.redirect("/admin_page")

app = webapp2.WSGIApplication([...
                                ('/add', Add),
                                ('/', MainPage)], debug=True)

In the Log Console, it doesn't reach the print("Test") line. 在Log Console中,它没有到达print("Test")行。 The log shows: 日志显示:

INFO     2013-09-07 13:14:42,423 server.py:528] "POST /add HTTP/1.1" 200 - 

And stuck there, it doesn't continue to run. 并停留在那里,它不会继续运行。

What might be the issue and how to solve it? 可能是什么问题以及如何解决?


Edit: 编辑:

The variable result recieves the right value, but the function doesn't perform the redirect: 变量result接收正确的值,但函数不执行重定向:

class Add(webapp2.RequestHandler):
    def post(self):
        ...
        logging.debug("result in main.py = %s", result)
        if result is 0:
            return self.redirect("/admin_page")


app = webapp2.WSGIApplication([...
                               ('/add', Add),
                               ('/', MainPage)], debug=True)

Log Console output: 日志控制台输出:

DEBUG    2013-09-07 12:36:07,167 main.py:362] result in main.py = 0

And it shows the blank page at: 它在以下位置显示空白页:

localhost:8080/add 本地主机:8080 /添加

Instead of using post you should write to the response: 而不是使用post您应该写响应:

self.response.write("Test")

In addition; 此外; you should not use print at all as appengine uses it for internal communication. 您不应完全使用print ,因为appengine会将其用于内部交流。

You need to return html from your App.post() method: 您需要从App.post()方法返回html:

self.response.write("<html><body>Test</body></html>")

or redirect to another page. 重定向到另一个页面。

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

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