googleappengine:从URL处理程序给脚本赋值?

2024-06-02 05:39:37 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我的app.yaml文件的一部分:

handlers:
- url: /remote_api
  script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
  login: admin
- url: /detail/(\d)+
  script: Detail.py
- url: /.*
  script: Index.py

我希望那个捕获组(由(\d)表示的那个)对脚本Detail.py可用。我该怎么做?在

我是否需要找到从Detail.py访问GET数据的方法?在

另外,当我导航到一个像/fff这样的URL时,它应该与Index.py处理程序相匹配,我只得到一个空白的响应。在


Tags: 文件pyapiappurlyamlindexremote
1条回答
网友
1楼 · 发布于 2024-06-02 05:39:37

我看到两个问题,如何将url路径的元素作为变量传递到处理程序中,以及如何使catch-all正确呈现。在

这两种方法都与处理程序中的main()方法有关,而不是应用程序yaml在

1)要在/detail/(\d)url中传递id,您需要如下所示:

class DetailHandler(webapp.RequestHandler):
    def get(self, detail_id):
      # put your code here, detail_id contains the passed variable

def main():
  # Note the wildcard placeholder in the url matcher
  application = webapp.WSGIApplication([('/details/(.*)', DetailHandler)]
  wsgiref.handlers.CGIHandler().run(application)

2)为了确保您的Index.py捕获所有内容,您需要这样的方法:

^{pr2}$

希望有帮助。在

相关问题 更多 >