diff options
| author | Tres Seaver <tseaver@palladion.com> | 2013-04-21 12:45:51 -0700 |
|---|---|---|
| committer | Tres Seaver <tseaver@palladion.com> | 2013-04-21 12:45:51 -0700 |
| commit | bc8d4d6f14725901eb5acb1d78889be465dc20e5 (patch) | |
| tree | 5fd24691edaa6dd57dfe92721cd2206f31a6ee56 /docs | |
| parent | c35b298f86b2591d7acd44ccb5b1e490269fca74 (diff) | |
| parent | 439a02a420d9014a56d01f7e08db89ec65d943c5 (diff) | |
| download | pyramid-bc8d4d6f14725901eb5acb1d78889be465dc20e5.tar.gz pyramid-bc8d4d6f14725901eb5acb1d78889be465dc20e5.tar.bz2 pyramid-bc8d4d6f14725901eb5acb1d78889be465dc20e5.zip | |
Merge pull request #987 from tshepang/diff
docs/narr/hooks.rst: some improvements
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/narr/hooks.rst | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst index 1bd294bd1..37a74b53a 100644 --- a/docs/narr/hooks.rst +++ b/docs/narr/hooks.rst @@ -14,8 +14,8 @@ in various ways. Changing the Not Found View --------------------------- -When :app:`Pyramid` can't map a URL to view code, it invokes a :term:`not -found view`, which is a :term:`view callable`. The default Not Found View +When :app:`Pyramid` can't map a URL to view code, it invokes a :term:`Not +Found View`, which is a :term:`view callable`. The default Not Found View can be overridden through application configuration. If your application uses :term:`imperative configuration`, you can replace @@ -25,15 +25,17 @@ the Not Found View by using the .. code-block:: python :linenos: - from helloworld.views import notfound - config.add_notfound_view(notfound) + def notfound(request): + return Response('Not Found, dude', status='404 Not Found') -Replace ``helloworld.views.notfound`` with a reference to the :term:`view -callable` you want to use to represent the Not Found View. The :term:`not -found view` callable is a view callable like any other. + def main(globals, **settings): + config = Configurator() + config.add_notfound_view(notfound) + +The :term:`Not Found View` callable is a view callable like any other. If your application instead uses :class:`pyramid.view.view_config` decorators -and a :term:`scan`, you can replace the Not Found view by using the +and a :term:`scan`, you can replace the Not Found View by using the :class:`pyramid.view.notfound_view_config` decorator: .. code-block:: python @@ -46,8 +48,8 @@ and a :term:`scan`, you can replace the Not Found view by using the return Response('Not Found, dude', status='404 Not Found') def main(globals, **settings): - config = Configurator() - config.scan() + config = Configurator() + config.scan() This does exactly what the imperative example above showed. @@ -154,12 +156,12 @@ forbidden view: .. code-block:: python :linenos: - from helloworld.views import forbidden_view - from pyramid.httpexceptions import HTTPForbidden - config.add_forbidden_view(forbidden_view) + def forbidden(request): + return Response('forbidden') -Replace ``helloworld.views.forbidden_view`` with a reference to the Python -:term:`view callable` you want to use to represent the Forbidden view. + def main(globals, **settings): + config = Configurator() + config.add_forbidden_view(forbidden_view) If instead you prefer to use decorators and a :term:`scan`, you can use the :class:`pyramid.view.forbidden_view_config` decorator to mark a view callable |
