Pyramid中如何配置多种URL匹配同一个View
2012-07-22 09:26
423 查看
在pylons中,通过配置Route可以很容易地配置不同的URL指向同一个controller的Action.
但是在pyramid中,如果我们这样做,
则会出现如下错误
pyramid.exceptions.ConfigurationConflictError
正确的实现方法是:
你需要为不同的URL配置不同的Route name(在单个application中是不允许有重复的route name):
然后为这些route配置相同的view
如果是用@view_config decorator:
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): ........
相关文章推荐
- 如何处理一个tableView中同种model多种cell相同逻辑的情况?
- SpringMVC学习系列(3) 之 URL请求到Action的映射规则 在系列(2)中我们展示了一个简单的get请求,并返回了一个简单的helloworld页面。本篇我们来学习如何来配置一个acti
- 在一个tableView 中需要自定义多种样式的cell(两种或三种),通常你如何实现,说说思路即可?
- Android如何在一个TextView中实现多种文本风格?
- Android如何在一个TextView中实现多种文本风格?
- rails 路由配置时 URL 地址如何匹配下划线?
- 如何优雅地加载一个properties配置文件
- 当在浏览器中输入一个url后回车,后台发生了什么?比如输入url后,你看到了百度的首页,那么这一切是如何发生的呢?
- 如何查看一个URL是否命中CDN缓存
- 如何配置View事件日志数据库使用SQL Express
- 让一个软件系统同时支持多个多种数据库灵活配置,让客户可以任意配置各个核心数据库部分
- 如何自定义View及在配置文件中增加描述属性
- 一个Filter配置多个url-pattern
- 如何给一个View同时设置圆角和阴影
- 如何将Eclipse的一个工作空间的配置文件复制到另一个工作空间
- 如何使用ps将同一个文字的颜色分为上下或者左右两种甚至多种、、
- PHP如何解析一个ini的配置文件?
- 在tomcat中如何配置访问的时候不需要在URL中加入项目名
- SEO 技巧,如何设计一个高质量的 URL 和标题