适用于Google App Engine的脚本处理程序

时间:2012-11-25 06:13:35

标签: python google-app-engine

我正在尝试使用Google App Engine中的Python进行学习,但无法让教程发挥作用。但最终,我想编写一个Python脚本,将服务器中文件夹中的文件列表返回给JavaScript。

以下是我目前的情况:

+MainProj  
   + static  
      +scripts  
          . __init__.py  
          . helloworld.py  
   . app.yaml

在helloworld.py中

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, webapp2 World!')
app = webapp2.WSGIApplication([('/.*', MainPage)], debug=True)

在app.yaml

application: applicationname
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /.*
  script: static.scripts.helloworld.app

我收到服务器错误

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

任何人都可以帮助我的设置出错?

2 个答案:

答案 0 :(得分:3)

包裹路径中的每个文件夹(' static.scripts.helloworld.app')都需要__init__.py才能正确导入,因此要么添加一个'静态&# 39;或者(更明智的是,在我看来)将helloworld.py移到顶部,并使用' helloworld.app'在你的app.yaml。

答案 1 :(得分:-1)

app.yaml处理程序所需要的只是:

 - url: /.*
   script: static.scripts.helloworld.py

并确保您的helloworld.py底部代码中还有实际启动应用程序和监听器的内容:

from google.appengine.ext.webapp import util
# granted, you might want to replace "webapp" with "webapp2" here

def main():
    util.run_wsgi_app(app)

if __name__ == '__main__':
    main()