summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2015-01-01 23:51:48 -0600
committerMichael Merickel <michael@merickel.org>2015-01-01 23:51:48 -0600
commit0414b7c7b2e3ea45d4dcbdf273a9e332238a0f50 (patch)
tree624e02d9edf442a748e592e289130c9604552afa /docs
parent568b583af39880991470a5a23b2f1d5755f7c566 (diff)
parent303abc8b585d97c75773b3cfa48b6e748c96fd64 (diff)
downloadpyramid-0414b7c7b2e3ea45d4dcbdf273a9e332238a0f50.tar.gz
pyramid-0414b7c7b2e3ea45d4dcbdf273a9e332238a0f50.tar.bz2
pyramid-0414b7c7b2e3ea45d4dcbdf273a9e332238a0f50.zip
Merge pull request #1499 from sontek/expose_response_class
Expose response class
Diffstat (limited to 'docs')
-rw-r--r--docs/glossary.rst4
-rw-r--r--docs/narr/hooks.rst47
2 files changed, 51 insertions, 0 deletions
diff --git a/docs/glossary.rst b/docs/glossary.rst
index 01300a0be..911c22075 100644
--- a/docs/glossary.rst
+++ b/docs/glossary.rst
@@ -16,6 +16,10 @@ Glossary
An object which, provided a :term:`WSGI` environment as a single
positional argument, returns a Pyramid-compatible request.
+ response factory
+ An object which, provided a :term:`request` as a single positional
+ argument, returns a Pyramid-compatible response.
+
response
An object returned by a :term:`view callable` that represents response
data returned to the requesting user agent. It must implement the
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst
index 4da36e730..e250c2d7e 100644
--- a/docs/narr/hooks.rst
+++ b/docs/narr/hooks.rst
@@ -354,6 +354,53 @@ We attach and cache an object named ``extra`` to the ``request`` object.
.. _beforerender_event:
+.. 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())
+
+
Using The Before Render Event
-----------------------------