【发布时间】:2013-12-13 12:29:31
【问题描述】:
我一直在尝试 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()
如您所见,控制台没有报告错误,但在浏览器中查看时,空白屏幕盯着我。我错过了什么吗?
【问题讨论】:
-
你的 index.html 的内容是什么?
标签: python google-app-engine web-applications