在pylons中,通过配置Route可以很容易地配置不同的URL指向同一个controller的Action.

map.connect('/:page/category{categoryid}/pageindex{pageindex}/{id}', controller='front',action='index')
map.connect('/:page/category{categoryid}/pageindex{pageindex}/{id}/', controller='front',action='index')

但是在pyramid中,如果我们这样做,

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

则会出现如下错误

pyramid.exceptions.ConfigurationConflictError

正确的实现方法是:

你需要为不同的URL配置不同的Route name(在单个application中是不允许有重复的route name):

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

然后为这些route配置相同的view

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

如果是用@view_config decorator:

@view_config(route_name='home')
@view_config(route_name='home1')
def your_method(request):
      ........

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-02
  • 2021-10-19
  • 2021-05-28
  • 2022-12-23
  • 2021-11-19
  • 2021-10-23
  • 2022-12-23
相关资源
相似解决方案