Nic*_*ner 2 python google-app-engine
这是我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
Run Code Online (Sandbox Code Playgroud)
我希望该捕获组(表示的那个(\d))可用于脚本Detail.py.我怎样才能做到这一点?
我是否需要找出一种从中访问GET数据的方法Detail.py?
此外,当我导航到一个类似于/fff应该与Index.py处理程序匹配的URL时,我只得到一个空白的响应.
Jac*_*ler 11
我看到两个问题,如何将url路径的元素作为变量传递给处理程序,以及如何使catch-all正确呈现.
这两者都与处理程序中的main()方法有关,而不是app.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)
Run Code Online (Sandbox Code Playgroud)
2)为了确保你Index.py抓住一切,你想要这样的东西:
class IndexHandler(webapp.RequestHandler):
def get(self):
# put your handler code here
def main():
# Note the wildcard without parens
application = webapp.WSGIApplication([('/.*', IndexHandler)]
wsgiref.handlers.CGIHandler().run(application)
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
2957 次 |
| 最近记录: |