julx
julx

Reputation: 9091

Multiple paths for a route in URL Dispatch

I use URL Dispatch in Pyramid framework. As far as I can see, there is a requirement that each route has a unique name. Is there a way to associate multiple paths with a single route? In particular, I would like to have two different addresses display the same content. Note: I don't want to perform redirection.

Upvotes: 2

Views: 825

Answers (2)

Jonathan Vanasco
Jonathan Vanasco

Reputation: 15690

do you mean something like this...

in your config:

config.add_route('path::a', 'path/a')
config.add_route('path::b', 'path/b')

in your views:

class ViewClass(handlerClass):
    @view_config(renderer="/path.mako",route_name="path::a")
    @view_config(renderer="/path.mako",route_name="path::b")
    def path(self):
        return {'project':'MyApp'}

Upvotes: 3

Senthil Kumaran
Senthil Kumaran

Reputation: 56951

You mean, two different paths to be handled by a single controller / view? Is something like this you are looking for?

 config.add_route('idea', 'path/{id}')
 config.add_route('newidea', 'newpath/{id}')
 config.add_view('mypackage.views.site_view', route_name='idea')
 config.add_view('mypackage.views.site_view', route_name='newidea')

Upvotes: 3

Related Questions