diff options
| author | Chris McDonough <chrism@agendaless.com> | 2010-08-07 04:41:40 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2010-08-07 04:41:40 +0000 |
| commit | ab27bdb42d5b2c525466fe5570959f66b4814326 (patch) | |
| tree | e845ef721f21e4b651cd5bfcd32564ff18525855 /repoze/bfg/tests | |
| parent | a48be71bca1caec1082061430f5787a0ebf7c249 (diff) | |
| download | pyramid-ab27bdb42d5b2c525466fe5570959f66b4814326.tar.gz pyramid-ab27bdb42d5b2c525466fe5570959f66b4814326.tar.bz2 pyramid-ab27bdb42d5b2c525466fe5570959f66b4814326.zip | |
Features
--------
- There can only be one Not Found view in any ``repoze.bfg``
application. If you use
``repoze.bfg.view.append_slash_notfound_view`` as the Not Found
view, it still must generate a NotFound response when it cannot
redirect to a slash-appended URL; this not found response will be
visible to site users.
As of this release, if you wish to use a custom notfound view
callable when ``append_slash_notfound_view`` does not redirect to a
slash-appended URL, use a wrapper function as the
``repoze.bfg.exceptions.NotFound`` view; have this wrapper attach a
view callable which returns a response to the request object named
``custom_notfound_view`` before calling
``append_slash_notfound_view``. For example::
from webob.exc import HTTPNotFound
from repoze.bfg.exceptions import NotFound
from repoze.bfg.view import append_slash_notfound_view
def notfound_view(exc, request):
def fallback_notfound_view(exc, request):
return HTTPNotFound('It aint there, stop trying!')
request.fallback_notfound_view = fallback_notfound_view
return append_slash_notfound_view(exc, request)
config.add_view(notfound_view, context=NotFound)
``custom_notfound_view`` must adhere to the two-argument view
callable calling convention of ``(context, request)`` (``context``
will be the exception object).
If ``custom_notfound_view`` is not found on the request object, a
default notfound response will be generated when the
``append_slash_notfound_view`` doesn't redirect to a slash-appended
URL.
Documentation
--------------
- Expanded the "Cleaning Up After a Request" section of the URL
Dispatch narrative chapter.
- Expanded the "Redirecting to Slash-Appended Routes" section of the
URL Dispatch narrative chapter.
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_view.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_view.py b/repoze/bfg/tests/test_view.py index bb178029c..27f468c74 100644 --- a/repoze/bfg/tests/test_view.py +++ b/repoze/bfg/tests/test_view.py @@ -429,6 +429,15 @@ class AppendSlashNotFoundView(BaseTest, unittest.TestCase): response = self._callFUT(context, request) self.assertEqual(response.status, '404 Not Found') + def test_custom_notfound_view(self): + request = self._makeRequest(PATH_INFO='/abc') + def notfound(exc, request): + return 'abc' + request.custom_notfound_view = notfound + context = Exception() + response = self._callFUT(context, request) + self.assertEqual(response, 'abc') + def test_no_path(self): request = self._makeRequest() context = Exception() |
