使URL指向App Engine中的.py文件

Noa*_*ark 4 python url google-app-engine

我现在正在深入研究GAE,我看到两种方法可以使特定的URL拉到正确的页面.

第一种方法是使用处理程序:

handlers:
  - url: /.*
    script: helloworld.py
Run Code Online (Sandbox Code Playgroud)

另一种方法是使用以下方法:

application = webapp.WSGIApplication(
                                 [('/', MainPage),
                                  ('/sign', Guestbook)],
                                 debug=True)
Run Code Online (Sandbox Code Playgroud)

哪个更好或哪个更好?我不完全理解第二个例子究竟在做什么.

Rob*_*uin 7

你需要同时使用它们.app.yaml中的部分告诉App Engine在哪里查找您的WSGI应用程序. application = webapp.WSGIApplication(...)使用webapp框架设置您的WSGI应用程序.

更新:

app.yaml中:

handlers:
  - url: /city.*
    script: cityhandler.py
Run Code Online (Sandbox Code Playgroud)

cityhandler.py

application = webapp.WSGIApplication([('/city', ShowCityPage)],
                                     debug=True)
Run Code Online (Sandbox Code Playgroud)