Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map different URLs to same view

Tags:

python

pyramid

It seems trivial enough but I can't find a valid answer to this problem.

Suppose I have two different links '/' and '/home' and I want them to point to the same view. (This means whether user opens xyz.com or xyz.com/home, same page will be displayed).

In pyramid I tried

config.add_route('home','/')
config.add_route('home','home/')

But it raises the following exception

pyramid.exceptions.ConfigurationConflictError: Conflicting configuration actions
  For: ('route', 'home')

How should I actually implement this?

like image 788
RedBaron Avatar asked Apr 30 '12 12:04

RedBaron


1 Answers

You need to add them under different route names (they must be unique per application):

config.add_route('home','/')
config.add_route('home1','home/')

and then configure the same view for both:

config.add_view(yourview, route_name='home')
config.add_view(yourview, route_name='home1')

or, in case of using @view_config decorator, double-decorate your method:

@view_config(route_name='home')
@view_config(route_name='home1') 
def your_method(request):
   ..... 
like image 137
soulcheck Avatar answered Oct 22 '22 08:10

soulcheck