Skip to content

supporting subroute #7

wants to merge 1 commit into from

2 participants

aodag commented Jun 28, 2011

directive to register nested routes.


 add_route('hamm', '/hamm')
 add_subroute('hamm', 'egg', '{var}/egg')

mapping results::

 route_path('hamm', request) => /hamm
 route_path('egg', request, var='spam') => /hamm/spam/egg
Pylons Project member
mcdonc commented Jun 29, 2011

This is a nice idea.

How about something like this as a pattern in Pyramid itself:

# in pyramid

class Configurator(object):
    def with_root_route(self, route_name):
        if not self.routes_mapper.has_route(route_name):
            raise ConfigurationError
        configurator = self.__class__(registry=self.registry,
        configurator.root_route_name = route_name
        return configurator

    def mount(self, function, route_name):
        function = self.maybe_dotted(function)
        config = self.with_root_route(route_name)

    def add_route(self, *arg, **kw):
        # .. do what add_route currently does now but taking into account
        # that there might be a root_route_name in effect on self (ie. it
        # would do what your current add_subroute does in that case) ...

# in "master" package

if __name__ == '__main__':
    config = Configurator()
    config.add_route('sub', '/sub')
    config.mount('otherpkg.subapp', 'sub')

# in "otherpkg" package:

def subapp(config):
    config.add_route('hello', '/hello')
    # would actually register as '/sub/hello' when called via "mount"
aodag commented Jun 29, 2011

It's nice to improve modulability with routes.
I wanna contribute to that feature for subapplication mounting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.