Python 页码为';不一定
在GoogleAppEngine中,我有以下代码显示一个简单的HTML页面Python 页码为';不一定,python,google-app-engine,Python,Google App Engine,在GoogleAppEngine中,我有以下代码显示一个简单的HTML页面 import os from google.appengine.ext.webapp import template from google.appengine.ext import webapp class IndexHandler(webapp.RequestHandler): def get(self): template_values = { } path = os.path.join(
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
class IndexHandler(webapp.RequestHandler):
def get(self):
template_values = { }
path = os.path.join(os.path.dirname(__file__), '../templates/index.html')
self.response.out.write(template.render(path, template_values))
问题是页面并不总是呈现。html是一个简单的“helloworld!”。经过几次页面刷新后,页面将正确显示(即找到index.html文件…)。最后我试着打电话给弗拉什,但没用。我可以用SDK和他们的服务器重新编程
我错过什么了吗?有人知道发生了什么吗
感谢无法复制-随着目录更改为/templates
(在我的设置中没有./templates
),并添加了通常的main
函数,并且该脚本在app.yaml
中分配给某个任意URL,它每次都能成功地为“Hello World”服务。我想我们需要更多的信息来帮助——日志条目(可能在此处添加logging.info
调用?),app.yaml
,where'smain
,等等。您的处理程序脚本(app.yaml引用的脚本)有一个main()函数,但结尾需要这个节:
if __name__ == '__main__':
main()
发生的情况是,第一次在给定的解释器中运行脚本时,它会解释主脚本,而主脚本什么也不做(因此返回一个空白响应)。在随后的调用中,解释器只执行main()(一个有文档记录的优化),它会按预期生成页面。添加上面的节也会导致它在初始导入时执行main