summaryrefslogtreecommitdiff
path: root/repoze/bfg/router.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-07-08 14:25:46 +0000
committerChris McDonough <chrism@agendaless.com>2008-07-08 14:25:46 +0000
commita1f12be881a025d0640052554e8d53cdfe19afa9 (patch)
treede2fd7cf49a7307c3fed92f5bdd18d4804d019ac /repoze/bfg/router.py
parent41aeaa3c4c22380f076c1989cfd1b52600751286 (diff)
downloadpyramid-a1f12be881a025d0640052554e8d53cdfe19afa9.tar.gz
pyramid-a1f12be881a025d0640052554e8d53cdfe19afa9.tar.bz2
pyramid-a1f12be881a025d0640052554e8d53cdfe19afa9.zip
Redirect on default view if name doesn't end with slash.
Rejigger sample app, adding more templates.
Diffstat (limited to 'repoze/bfg/router.py')
-rw-r--r--repoze/bfg/router.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py
index a15ac0e62..efc7406b6 100644
--- a/repoze/bfg/router.py
+++ b/repoze/bfg/router.py
@@ -4,6 +4,7 @@ from zope.interface import directlyProvides
from webob import Request
from webob.exc import HTTPNotFound
+from webob.exc import HTTPFound
from repoze.bfg.interfaces import IPublishTraverserFactory
from repoze.bfg.interfaces import IViewFactory
@@ -24,13 +25,19 @@ class Router:
path = environ.get('PATH_INFO', '/')
traverser = getMultiAdapter((root, request), IPublishTraverserFactory)
context, name, subpath = traverser(path)
- request.subpath = subpath
- app = queryMultiAdapter((context, request), IViewFactory, name=name,
- default=_marker)
- if app is _marker:
- app = HTTPNotFound(request.url)
+ if (not name) and (not path.endswith('/')):
+ # if this is the default view of the context, and the URL
+ # doesn't end in a slash, redirect to the url + '/' (so we
+ # don't have to play base tag games)
+ app = HTTPFound(add_slash=True)
else:
- app = getMultiAdapter((app, request), IWSGIApplicationFactory)
+ request.subpath = subpath
+ app = queryMultiAdapter((context, request), IViewFactory, name=name,
+ default=_marker)
+ if app is _marker:
+ app = HTTPNotFound(request.url)
+ else:
+ app = getMultiAdapter((app, request), IWSGIApplicationFactory)
return app(environ, start_response)
def make_app(root_policy, package=None, filename='configure.zcml'):