繁体   English   中英

Google App Engine-浏览器上的空白页但没有错误

[英]Google App Engine - Blank Page on Browser but No Error

我一直在尝试GAE / Python,并从“使用Google App Engine”一书中举例说明。 在开始获取空白的浏览器页面之前,我修改了主要的python文件之前,我无法正常工作。

日志控制台

INFO     2013-12-13 21:17:34,568 module.py:617] default: "GET / HTTP/1.1" 200 -
INFO     2013-12-13 21:17:34,737 module.py:617] default: "GET /favicon.ico HTTP/1.1" 200 -

index.py

我不确定我缺少什么,但这是python代码。

import os
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template


def doRender(handler, tname='index.html', values={}):
    #Check if the template file tname exists

    temp = os.path.join(os.path.dirname(__file__),
         'template/' + tname)
    if not os.path.isfile(temp):
        return False

    # If template file exisis, make a copy and add the path
    newval = dict(values)
    newval['path'] = handler.request.path
    outstr = template.render(temp, newval)
    handler.response.out.write(str(outstr))
    return True


class LoginHandler(webapp.RequestHandler):

    def get(self):
        doRender(self, 'loginscreen.html')

    def post(self):
        acct = self.request.get('account')
        pw = self.request.get('password')
        logging.info('Checking account = '+acct+' pw='+pw)

        if pw == '' or acct == '':
            doRender(self, 'loginscreen.html', {'error': 'Please specify Account and Password'} )
        elif pw == 'secret':
            doRender(self, 'loggedin.html', {})
        else:
            doRender(self, 'loginscreen.html', {'error': 'Incorrect password'} )



class MainHandler(webapp.RequestHandler):

    def get(self):
        if doRender(self, self.request.path):
            return
        doRender(self, 'index.html')




def main():
    application = webapp.WSGIApplication([
        ('/login', LoginHandler),
        ('/.*', MainHandler)],
        debug=True)
    wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
    main()

如您所见,控制台未报告任何错误,但是在浏览器中查看时,空白屏幕向我回望。 我想念什么吗?

首先,我认为您的教程已经过时了,因为它仍然使用webapp ,因此您现在应该使用webapp2

就是说,您的代码被作为App Engine模块处理,因此它正在寻找一个名为app的属性(在旧版本中,它是您的代码中所述的application )。 对于您而言,已将其包装在main()函数中,这解释了为什么它不再起作用了。

只要使您的代码看起来像这样,就可以了:

import os
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template


def doRender(handler, tname='index.html', values={}):
#Check if the template file tname exists

    temp = os.path.join(os.path.dirname(__file__),
         'template/' + tname)
    if not os.path.isfile(temp):
        return False

    # If template file exisis, make a copy and add the path
    newval = dict(values)
    newval['path'] = handler.request.path
    outstr = template.render(temp, newval)
    handler.response.out.write(str(outstr))
    return True

class LoginHandler(webapp.RequestHandler):

    def get(self):
        doRender(self, 'loginscreen.html')

    def post(self):
        acct = self.request.get('account')
        pw = self.request.get('password')
        logging.info('Checking account = '+acct+' pw='+pw)

        if pw == '' or acct == '':
            doRender(self, 'loginscreen.html', {'error': 'Please specify Account and Password'} )
        elif pw == 'secret':
            doRender(self, 'loggedin.html', {})
        else:
            doRender(self, 'loginscreen.html', {'error': 'Incorrect password'} )

class MainHandler(webapp.RequestHandler):

    def get(self):
        if doRender(self, self.request.path):
            return
        doRender(self, 'index.html')

app = webapp.WSGIApplication([
    ('/login', LoginHandler),
    ('/.*', MainHandler)],
    debug=True)

暂无
暂无

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

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