使用 WSGIAppl 和正则表达式分组的 Google App 引擎 Url 映射 需要帮助
以谷歌文档为例,
class BrowseHandler(webapp.RequestHandler):
> def get(self, category, product_id):
> # Display product with given ID in the given category.
>
>
> # Map URLs like /browse/(category)/(product_id) to
> BrowseHandler. application =
> webapp.WSGIApplication([(r'/browse/(.*)/(.*)',
> BrowseHandler)
> ],
> debug=True)
>
> def main():
> run_wsgi_app(application)
>
> if __name__ == '__main__':
> main()
我如何更改 regx 分组,以便产品 id 是可选的,
即 url http://yourdomain。 com/category 将被发送到当前上面示例中的浏览处理程序,您必须添加产品 ID 或至少在类别后面添加 /,
即
http://yourdomain.com/category/
r'/browse/(.)/(.)'
有什么想法吗?
take this example from google docs
class BrowseHandler(webapp.RequestHandler):
> def get(self, category, product_id):
> # Display product with given ID in the given category.
>
>
> # Map URLs like /browse/(category)/(product_id) to
> BrowseHandler. application =
> webapp.WSGIApplication([(r'/browse/(.*)/(.*)',
> BrowseHandler)
> ],
> debug=True)
>
> def main():
> run_wsgi_app(application)
>
> if __name__ == '__main__':
> main()
How can i change the regx groupings so that Product id is optional
ie the url http://yourdomain.com/category will be sent to the browse handler in the current above example you must add a product id or at least the / after the category
ie
http://yourdomain.com/category/
r'/browse/(.)/(.)'
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用映射到同一处理程序的两个正则表达式:
You can use two regular expressions mapped to same handler:
尝试添加一个“?”在正则表达式结束之前:
Try to add a "?" before the end of your regexp: