diff options
| author | Michael Merickel <michael@merickel.org> | 2015-02-06 01:12:24 -0600 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2015-02-06 01:12:24 -0600 |
| commit | b63f0c5f6e2f322bd9183d194b4aa774f9f4e93f (patch) | |
| tree | 695d4b5e5ae974d0770acfbe9b8231ea1c71288a /docs/narr/hooks.rst | |
| parent | d35a916095943b020f30acb90e878abe9bfd4fb1 (diff) | |
| parent | 4b13e0dfcdf47b3ef9befd529c0d78af8a2712d5 (diff) | |
| download | pyramid-b63f0c5f6e2f322bd9183d194b4aa774f9f4e93f.tar.gz pyramid-b63f0c5f6e2f322bd9183d194b4aa774f9f4e93f.tar.bz2 pyramid-b63f0c5f6e2f322bd9183d194b4aa774f9f4e93f.zip | |
Merge branch 'master' into feature.re-entrant-config
Diffstat (limited to 'docs/narr/hooks.rst')
| -rw-r--r-- | docs/narr/hooks.rst | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst index 4da36e730..17cae2c67 100644 --- a/docs/narr/hooks.rst +++ b/docs/narr/hooks.rst @@ -349,6 +349,52 @@ We attach and cache an object named ``extra`` to the ``request`` object. the property .. index:: + single: response factory + +.. _changing_the_response_factory: + +Changing the Response Factory +------------------------------- + +.. versionadded:: 1.6 + +Whenever :app:`Pyramid` returns a response from a view it creates a +:term:`response` object. By default, an instance of the +:class:`pyramid.response.Response` class is created to represent the response +object. + +The factory that :app:`Pyramid` uses to create a response object instance can be +changed by passing a ``response_factory`` argument to the constructor of the +:term:`configurator`. This argument can be either a callable or a +:term:`dotted Python name` representing a callable. + +.. code-block:: python + :linenos: + + from pyramid.response import Response + + class MyResponse(Response): + pass + + config = Configurator(response_factory=lambda r: MyResponse()) + +If you're doing imperative configuration, and you'd rather do it after you've +already constructed a :term:`configurator` it can also be registered via the +:meth:`pyramid.config.Configurator.set_response_factory` method: + +.. code-block:: python + :linenos: + + from pyramid.config import Configurator + from pyramid.response import Response + + class MyResponse(Response): + pass + + config = Configurator() + config.set_response_factory(lambda r: MyResponse()) + +.. index:: single: before render event single: adding renderer globals @@ -730,7 +776,7 @@ If you want to implement your own Response object instead of using the :class:`pyramid.response.Response` object in any capacity at all, you'll have to make sure the object implements every attribute and method outlined in :class:`pyramid.interfaces.IResponse` and you'll have to ensure that it uses -``zope.interface.implementer(IResponse)`` as a class decoratoror. +``zope.interface.implementer(IResponse)`` as a class decorator. .. code-block:: python :linenos: |
