[英]Q: google app engine app.yaml how to handle urls from within main.py?
I have a web site up and running with about 100 urls specified in my app.yaml file. 我有一个正在运行的网站,并在我的app.yaml文件中指定了大约100个URL。 Because app.yaml is limited to 100 urls, I am trying to figure out how to transfer the app.yaml specified routing instructions into main.py. 由于app.yaml的网址限制为100个,因此我试图找出如何将app.yaml指定的路由指令传输到main.py中。 I want modify (shorten) the app.yaml file to send all requests to main.py and then I want main.py to route the requests as app.yaml currently does. 我想修改(缩短)app.yaml文件以将所有请求发送到main.py,然后希望main.py像app.yaml当前一样将请求路由。 I have been experimenting with the three files below but can't get a response of "Hello from MainHandler in test1.py" if I request any url other than /test1. 我一直在尝试下面的三个文件,但是如果我请求除/ test1以外的任何URL,则无法得到“来自test1.py中MainHandler的Hello响应”。 Why am I not getting a browser response of "Hello from MainHandler in test1.py" request a url of /xyz? 为什么我没有得到浏览器响应“来自test1.py中MainHandler的Hello”,请求/ xyz的URL?
Test 1: 测试1:
Request: /test1 要求:/ test1
Response: Hello from MainHandler in test1.py 响应:您好来自test1.py中的MainHandler
Test 2: 测试2:
Request: /example 要求:/ example
Response: Hello from ExampleHandler in main.py 响应:来自main.py中的ExampleHandler的你好
Test3: TEST3:
Request: /xyz 要求:/ xyz
Response: Hello MainHandler in main.py 响应:main.py中的Hello MainHandler
Why doesn't Test3 above also result in a response of "Hello from MainHandler in test1.py" and how can I make this happen? 为什么上面的Test3还没有收到“来自MainHandler的test1.py中的Hello响应”,我该怎么做呢?
main.py: main.py:
#!/usr/bin/env python
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello MainHandler in main.py<br>')
import test1
test1.app
class ExampleHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello from ExampleHandler in main.py<br>')
app = webapp2.WSGIApplication([
('/example', ExampleHandler),
(r'.*', MainHandler)],
debug=True)
test1.py: test1.py:
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello from MainHandler in test1.py')
app = webapp2.WSGIApplication([(r'.*', MainHandler)], debug=True)
if __name__ == "__main__":
app
app.yaml: app.yaml中:
application: test-for-rr
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /test1
script: test1.app
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
The precedence hierarchy goes from app.yaml -> handlers specified in the program. 优先级层次结构来自程序中指定的app.yaml->处理程序。
/test1
, app.yaml
routes your request to test1.app
(because it matches the /test1
route) which routes your request to test1.MainHandler
. 当您点击/test1
, app.yaml
将您的请求路由到test1.app
(因为它与/test1
路由匹配),从而将您的请求路由到test1.MainHandler
。 /test3
, app.yaml
routes your request to main.app
(because it matches the .*
route) which routes your request to main.MainHandler
. 当您点击/test3
, app.yaml
将您的请求路由到main.app
(因为它匹配.*
路由),从而将您的请求路由到main.MainHandler
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.