diff options
| author | Chris McDonough <chrism@plope.com> | 2015-02-17 18:57:31 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2015-02-17 18:57:31 -0500 |
| commit | 4dacb8c24efe98cb14b3ef89f6c9a8b2fd196790 (patch) | |
| tree | 039ca762ddcf6e4946a2570136927d2773374969 /docs/narr/hooks.rst | |
| parent | c5802723a4ea035076573838138878caf01735c1 (diff) | |
| parent | 75f85c57e0f4d1069cef9feb6ab6182b5f651492 (diff) | |
| download | pyramid-4dacb8c24efe98cb14b3ef89f6c9a8b2fd196790.tar.gz pyramid-4dacb8c24efe98cb14b3ef89f6c9a8b2fd196790.tar.bz2 pyramid-4dacb8c24efe98cb14b3ef89f6c9a8b2fd196790.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
Diffstat (limited to 'docs/narr/hooks.rst')
| -rw-r--r-- | docs/narr/hooks.rst | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst index 4da36e730..4fd7670b9 100644 --- a/docs/narr/hooks.rst +++ b/docs/narr/hooks.rst @@ -349,6 +349,55 @@ 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 :class:`pyramid.interfaces.IResponseFactory` argument to +the constructor of the :term:`configurator`. This argument can be either a +callable or a :term:`dotted Python name` representing a callable. + +The factory takes a single positional argument, which is a :term:`Request` +object. The argument may be ``None``. + +.. 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 +779,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: |
