summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2015-03-15 16:04:43 -0400
committerChris McDonough <chrism@plope.com>2015-03-15 16:04:43 -0400
commit24358c9d1d474bb81ce423d270041464bc731ce9 (patch)
tree17908551f091ec2725bf011d017673b0dbc53bbc
parent9a77daceedd9b1449876f53413e6437ca39fc965 (diff)
downloadpyramid-24358c9d1d474bb81ce423d270041464bc731ce9.tar.gz
pyramid-24358c9d1d474bb81ce423d270041464bc731ce9.tar.bz2
pyramid-24358c9d1d474bb81ce423d270041464bc731ce9.zip
add docs to notfound_view_config decorator code, expand docs to inlcude an example
-rw-r--r--pyramid/config/views.py20
-rw-r--r--pyramid/view.py25
2 files changed, 42 insertions, 3 deletions
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index af2045da9..6be81163f 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -1703,11 +1703,25 @@ class ViewsConfiguratorMixin(object):
Pyramid will return the result of the view callable provided as
``view``, as normal.
- If ``append_slash`` implements IResponse then that will be used as the
- response class instead of the default of ``HTTPFound``.
+ If the argument provided as ``append_slash`` is not a boolean but
+ instead implements :class:`~pyramid.interfaces.IResponse`, the
+ append_slash logic will behave as if ``append_slash=True`` was passed,
+ but the provided class will be used as the response class instead of
+ the default :class:`~pyramid.httpexceptions.HTTPFound` response class
+ when a redirect is performed. For example:
+
+ .. code-block:: python
+
+ from pyramid.httpexceptions import HTTPMovedPermanently
+ config.add_notfound_view(append_slash=HTTPMovedPermanently)
+
+ The above means that a redirect to a slash-appended route will be
+ attempted, but instead of :class:`~pyramid.httpexceptions.HTTPFound`
+ being used, :class:`~pyramid.httpexceptions.HTTPMovedPermanently will
+ be used` for the redirect response if a slash-appended route is found.
- .. versionadded:: 1.3
.. versionchanged:: 1.6
+ .. versionadded:: 1.3
"""
for arg in ('name', 'permission', 'context', 'for_', 'http_cache'):
if arg in predicates:
diff --git a/pyramid/view.py b/pyramid/view.py
index a84dde83f..b30383003 100644
--- a/pyramid/view.py
+++ b/pyramid/view.py
@@ -332,6 +332,31 @@ class notfound_view_config(object):
redirect to the URL implied by the route; if it does not, Pyramid will
return the result of the view callable provided as ``view``, as normal.
+ If the argument provided as ``append_slash`` is not a boolean but
+ instead implements :class:`~pyramid.interfaces.IResponse`, the
+ append_slash logic will behave as if ``append_slash=True`` was passed,
+ but the provided class will be used as the response class instead of
+ the default :class:`~pyramid.httpexceptions.HTTPFound` response class
+ when a redirect is performed. For example:
+
+ .. code-block:: python
+
+ from pyramid.httpexceptions import (
+ HTTPMovedPermanently,
+ HTTPNotFound
+ )
+
+ @notfound_view_config(append_slash=HTTPMovedPermanently)
+ def aview(request):
+ return HTTPNotFound('not found')
+
+ The above means that a redirect to a slash-appended route will be
+ attempted, but instead of :class:`~pyramid.httpexceptions.HTTPFound`
+ being used, :class:`~pyramid.httpexceptions.HTTPMovedPermanently will
+ be used` for the redirect response if a slash-appended route is found.
+
+ .. versionchanged:: 1.6
+
See :ref:`changing_the_notfound_view` for detailed usage information.
"""