簡體   English   中英

Google App Engine:POST請求后為空白頁

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

當我在Web應用程序中單擊“添加”按鈕時,此地址顯示:

本地主機:8080 /添加

但頁面空白。

main.py:

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

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

在Log Console中,它沒有到達print("Test")行。 日志顯示:

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

並停留在那里,它不會繼續運行。

可能是什么問題以及如何解決?


編輯:

變量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)

日志控制台輸出:

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

它在以下位置顯示空白頁:

本地主機:8080 /添加

而不是使用post您應該寫響應:

self.response.write("Test")

此外; 您不應完全使用print ,因為appengine會將其用於內部交流。

您需要從App.post()方法返回html:

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

重定向到另一個頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM