简体   繁体   English

问:谷歌应用引擎app.yaml如何处理main.py中的网址?

[英]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->处理程序。

  • When you hit /test1 , app.yaml routes your request to test1.app (because it matches the /test1 route) which routes your request to test1.MainHandler . 当您点击/test1app.yaml将您的请求路由到test1.app (因为它与/test1路由匹配),从而将您的请求路由到test1.MainHandler
  • When you hit /test3 , app.yaml routes your request to main.app (because it matches the .* route) which routes your request to main.MainHandler . 当您点击/test3app.yaml将您的请求路由到main.app (因为它匹配.*路由),从而将您的请求路由到main.MainHandler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Google App Engine Python将变量从app.yaml传递到main.py. - How to pass a variable from app.yaml to main.py with Google App Engine Python main.py或app.yaml是否确定此示例中App Engine cron任务使用的URL? - Does main.py or app.yaml determine the URL used by the App Engine cron task in this example? 将 main.py 更改为 __init__.py 后,app.yaml 无法定位入口点 - app.yaml cannot locate entry point after changing main.py into __init__.py 在 Google App Engine 中部署 FLASK 应用程序时从 app.py 更改为 main.py - Change from app.py to main.py when deploying a FLASK app in Google App Engine 如何为Google App Engine应用程序写入`app.yaml`文件? - How to write `app.yaml` file for Google App Engine app? Google App Engine | Python |的app.yaml - Google App Engine | Python | APP.YAML 如何使用App Engine app.yaml文件中定义的路由从Google Cloud Storage提供内容? - How to serve content from Google Cloud Storage with routes defined in App Engine app.yaml file? Google应用程序引擎python cron:app.yaml文件中的testcron.py在做什么? - Google app engine python cron: What is the testcron.py doing in the app.yaml file? Google App Engine:运行dev_appserver.py app.yaml,但没有任何反应 - Google App Engine: run dev_appserver.py app.yaml but nothing happens app.yaml文件:运行2个Python文件Google App Engine - app.yaml file: Running 2 Python Files Google App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM