在webapp2中,如何获取所有路由URI的列表? [英] In webapp2, how can I get a list of all route URIs?

查看:67
本文介绍了在webapp2中,如何获取所有路由URI的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个典型的WSGI应用程序,如下所示:

I have a typical WSGI application like so:

app = webapp2.WSGIApplication([
    ('/site/path/one',     'package.module.ClassOne'),
    ('/site/path/two',     'package.module.ClassTwo'),
    ('/site/path/three',   'package.module.ClassThree'),
])

我希望稍后能够在我的应用程序中检索路由列表,例如在ClassOne中:

I would like to be able to retrieve the list of routes later in my application, say for example, in ClassOne:

class ClassOne(webapp2.RequestHandler):
    def get(self):
        print ''' list of routes (e.g. '/site/path/one', '/site/path/two', etc.) '''

推荐答案

看起来WSGIApplication具有

It looks like WSGIApplication has a router property

路由器具有

def __repr__(self):
        routes = self.match_routes + [v for k, v in \
            self.build_routes.iteritems() if v not in self.match_routes]

        return '<Router(%r)>' % routes

您的wsgiApplication实例是您的 webapp2.RequestHandler

Your wsgiApplication instance is a property of your webapp2.RequestHandler

所以我认为 request.app.router

所以希望有一种更简单的方法,但是如果没有,那么应该解决吗?

So hopefully there is a more straighforward way but if not the above should worK?

Webapp2在 http://webapp2.readthedocs.io/en上提供了非常不错的可搜索源代码./latest/

这篇关于在webapp2中,如何获取所有路由URI的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆