【问题标题】:GAE app.yaml Script Handling for scripts in subdirectories (python)GAE app.yaml 子目录中脚本的脚本处理(python)
【发布时间】:2013-11-16 15:21:12
【问题描述】:

我正在设置一个新的 GAE 项目,但我无法让子目录中的脚本正常工作。

编辑:如果我去localhost:8080/testing_desc.html 我没有任何错误,只是一个空白页面(查看源也是空白的)。我的根目录中的脚本正常工作。根目录和子目录中都有一个__init__.py

Python 脚本示例(“/testing/testing_desc.py”):

import webapp2 as webapp

class DescTstPage(webapp.RequestHandler):
    def get(self):
        html = 'This should work.'
        self.response.out.write(html)

app = webapp.WSGIApplication([('/.*', DescTstPage)], debug=True)

app.yaml:

application: blah
version: blah
runtime: python27
api_version: 1

default_expiration: "5d 12h"

threadsafe: false

libraries:
- name: webapp2
  version: latest


handlers:
- url: /                  <-- This one works
  script: main.app
- url: /index.html        <-- This does NOT work (??)
  script: main.app
- url: /(.*?)_desc.html   <-- Also does NOT work
  script: \1/\1_desc.app
#file not found
- url: /.*
  script: file_not_found.app

我也尝试过更简单的 yaml 版本:

-url: /testing_desc.html
 script: /testing/testing_desc.app

【问题讨论】:

  • 您尝试过更改处理程序的顺序吗?把更具体的放在首位? (只是猜测)
  • 我通过将 main.pyapp = webapp.WSGIApplication([('/', DescTstPage)], debug=True) 更改为 app = webapp.WSGIApplication([('/.*', DescTstPage)], debug=True) 来使 /index.html 正常工作

标签: python google-app-engine wsgi webapp2 app.yaml


【解决方案1】:

当您使用 WSGI Pyhon27 时,这将起作用。使用点作为分隔符:

-url: /testing_desc.html
 script: /testing.testing_desc.app

【讨论】:

    【解决方案2】:

    答案在这里: How can i use script in sub folders on gae?

    它没有明确说明,但在答案中,您必须在 WSGIApplication 调用中将 /foo/ 更改为 /foo,该调用映射到 www.bar.com/foo。如果要映射到www.bar.com/foo.html,则需要在WSGIApplication 调用中将/foo 更改为/foo.*,并将app.yaml 中的url 处理程序更改为- url: /foo\.html

    【讨论】:

      【解决方案3】:

      为了让我的脚本在子目录中运行,我将 app.yaml/testing/testing_desc.py 更改为:

      app.yaml:

      - url: /testing.html
        script: testing/testing_desc.py
      

      /testing/testing_desc.py:

      app = webapp.WSGIApplication([('/.*', DescTstPage),], debug=True)
      
      def main():
          run_wsgi_app(app)
      
      if __name__ == '__main__':
          main()
      

      ATM 我不明白如何使路由与子目录一起工作,所以我将使用它。

      【讨论】:

        【解决方案4】:

        您正在将一个路由列表传递给您的 WSGIApplicaiton 调用。这些路由必须与正在处理的任何 URL 匹配。 ('/', DescTstPage) 只是将“/” URL 匹配到您的处理程序。 /.* 匹配所有路由。

        你在testing/testing_desc.app中设置了什么路线?它们必须匹配/testing_desc.html

        【讨论】:

          猜你喜欢
          • 2015-09-11
          • 2011-11-09
          • 1970-01-01
          • 2019-07-01
          • 1970-01-01
          • 1970-01-01
          • 2016-09-30
          • 2013-07-11
          • 1970-01-01
          相关资源
          最近更新 更多