summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-09-17 06:14:27 +0000
committerChris McDonough <chrism@agendaless.com>2009-09-17 06:14:27 +0000
commit19473e78e61ad084f07a0f7820a75b6c64d93dcd (patch)
tree77de1251af1041601adae3017060c46eef4739d1 /docs
parent550e16bb5936f5e22954992e50ac57f7f5cff4e0 (diff)
downloadpyramid-19473e78e61ad084f07a0f7820a75b6c64d93dcd.tar.gz
pyramid-19473e78e61ad084f07a0f7820a75b6c64d93dcd.tar.bz2
pyramid-19473e78e61ad084f07a0f7820a75b6c64d93dcd.zip
- Add a ``string`` renderer. This renderer converts a non-Response
return value of any view callble into a string. It is documented in the "Views" narrative chapter.
Diffstat (limited to 'docs')
-rw-r--r--docs/narr/views.rst35
1 files changed, 34 insertions, 1 deletions
diff --git a/docs/narr/views.rst b/docs/narr/views.rst
index 74d95480c..b64fd2a4b 100644
--- a/docs/narr/views.rst
+++ b/docs/narr/views.rst
@@ -795,6 +795,39 @@ Several built-in "renderers" exist in :mod:`repoze.bfg`. These
renderers can be used in the ``renderer`` attribute of view
configurations.
+``string``: String Renderer
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The ``string`` renderer is a renderer which renders a view callable
+result to a string. If a view callable returns a non-Response object,
+and the ``string`` renderer is associated in that view's
+configuration, the result will be to run the object through the Python
+``str`` function to generate a string. Note that if a Unicode object
+is returned, it is not ``str()`` -ified.
+
+Here's an example of a view that returns a dictionary. If the
+``string`` renderer is specified in the configuration for this view,
+the view will render the returned dictionary to the ``str()``
+representation of the dictionary:
+
+.. code-block:: python
+ :linenos:
+
+ from webob import Response
+ from repoze.bfg.view import bfg_view
+
+ @bfg_view(renderer='string')
+ def hello_world(context, request):
+ return {'content':'Hello!'}
+
+The body of the response returned by such a view will be a string
+representing the ``str()`` serialization of the return value:
+
+.. code-block: python
+ :linenos:
+
+ {'content': 'Hello!'}
+
``json``: JSON Renderer
~~~~~~~~~~~~~~~~~~~~~~~
@@ -802,7 +835,7 @@ The ``json`` renderer is a renderer which renders view callable
results to :term:`JSON`. If a view callable returns a non-Response
object it is called. It passes the return value through the
``simplejson.dumps`` function, and wraps the result in a response
-object. For example:
+object.
Here's an example of a view that returns a dictionary. If the
``json`` renderer is specified in the configuration for this view, the