diff options
| author | Chris McDonough <chrism@plope.com> | 2015-04-02 13:57:30 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2015-04-02 13:57:30 -0400 |
| commit | 45ddb5a5b744aebeac6004e9dba1c03d5bc8c50f (patch) | |
| tree | 9efe59281dbc0b20b9a94b69ee0a18bcb124aa93 /docs/narr/hooks.rst | |
| parent | b6498fce8c1418f3c7b33d31aa9c151a86bc4166 (diff) | |
| parent | 575ff8050b0cbdbf424947361f419b803568e122 (diff) | |
| download | pyramid-45ddb5a5b744aebeac6004e9dba1c03d5bc8c50f.tar.gz pyramid-45ddb5a5b744aebeac6004e9dba1c03d5bc8c50f.tar.bz2 pyramid-45ddb5a5b744aebeac6004e9dba1c03d5bc8c50f.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: |
