diff options
| author | Michael Merickel <michael@merickel.org> | 2015-05-27 10:29:21 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2015-05-27 10:46:02 -0500 |
| commit | 6e0f02a1e2d6fdece760f5ce1e61850b9514897d (patch) | |
| tree | fedee0e4cb586023771ad82f222f57d416ce58be /docs/narr/viewconfig.rst | |
| parent | 2f442c38710c7ca08a2feb43304c365e9b525c70 (diff) | |
| download | pyramid-6e0f02a1e2d6fdece760f5ce1e61850b9514897d.tar.gz pyramid-6e0f02a1e2d6fdece760f5ce1e61850b9514897d.tar.bz2 pyramid-6e0f02a1e2d6fdece760f5ce1e61850b9514897d.zip | |
add an example decorator showing a response being used unconditionally
Diffstat (limited to 'docs/narr/viewconfig.rst')
| -rw-r--r-- | docs/narr/viewconfig.rst | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/docs/narr/viewconfig.rst b/docs/narr/viewconfig.rst index d5203c6ba..fc5ae6dc6 100644 --- a/docs/narr/viewconfig.rst +++ b/docs/narr/viewconfig.rst @@ -234,6 +234,21 @@ Non-Predicate Arguments def myview(request): ... + All view callables in the decorator chain must return a response object + implementing :class:`pyramid.interfaces.IResponse` or raise an exception: + + .. code-block:: python + + def log_timer(wrapped): + def wrapper(context, request): + start = time.time() + response = wrapped(context, request) + duration = time.time() - start + response.headers['X-View-Time'] = '%.3f' % (duration,) + log.info('view took %.3f seconds', duration) + return response + return wrapper + ``mapper`` A Python object or :term:`dotted Python name` which refers to a :term:`view mapper`, or ``None``. By default it is ``None``, which indicates that the |
