Google app engine GAE WSGI应用程序URL映射
我有一个应用程序引擎项目结构设置,如下所示:Google app engine GAE WSGI应用程序URL映射,google-app-engine,Google App Engine,我有一个应用程序引擎项目结构设置,如下所示: ProjectRoot app.yaml 指数yaml main.py 静态[目录] index.html 应用程序[目录] 脚本1.py 脚本2.py 我的app.yaml看起来像这样 application: appname version: 1 runtime: python27 api_version: 1 threadsafe: no handlers: - url: /(.*\.html) mime_type: t
- ProjectRoot
- app.yaml
- 指数yaml
- main.py
- 静态[目录]
- index.html
- 应用程序[目录]
- 脚本1.py
- 脚本2.py
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: no
handlers:
- url: /(.*\.html)
mime_type: text/html
static_files: static/\1
upload: static/(.*\.html)
expiration: "1h"
# application scripts
- url: /app/(.+)
script: main.py
# index files
- url: /(.+)/
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
- url: /(.+)
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
# site root
- url: /
static_files: static/index.html
upload: static/index.html
expiration: "15m"
libraries:
- name: webapp2
version: "2.5.1"
My main.py只是默认的“Hello World”示例应用程序:
#!/usr/bin/env python
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write('Hello world!')
#print("Executing script!")
app = webapp2.WSGIApplication([(r'/app/(.*)', MainHandler)],
debug=True)
现在,可以按预期访问静态html了。到app.yaml中指定的main.py脚本的url映射工作正常,我知道脚本正在执行。我遇到的问题是main.py中要指定给WSGIApplication的URL映射。我希望能够使用url:localhost:808x/app/something访问应用程序脚本
我已经尝试使用以下模式:
r'/app/(.*)'
r'/(.*)'
r'/'
r'/app/'
上述模式都不会导致调用“get”响应处理程序(即,我没有得到“helloworld”响应)。我试图从文件中找出我做错了什么。我想这一切都归结为我刚刚开始接触正则表达式。有人能告诉我需要将应用程序处理程序映射到什么模式吗?这个模式怎么样
r'/app/.*'
如果存在任何regexp分组,则需要查看函数的参数
此外,如果以main.py
等格式指定脚本,则需要在main.py中添加main()函数。main()函数如下所示:
from google.appengine.ext.webapp.util import run_wsgi_app
...
...
def main():
run_wsgi_app(app)
if __name__ == '__main__':
main()
您也可以使用此表单:
script: main.app
对于后一种形式,您不需要main()函数。这个模式怎么样
r'/app/.*'
如果存在任何regexp分组,则需要查看函数的参数
此外,如果以main.py
等格式指定脚本,则需要在main.py中添加main()函数。main()函数如下所示:
from google.appengine.ext.webapp.util import run_wsgi_app
...
...
def main():
run_wsgi_app(app)
if __name__ == '__main__':
main()
您也可以使用此表单:
script: main.app
对于后一种形式,您不需要main()函数。不,这似乎不能解决它。不,这似乎不能解决它。