summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-06-18 21:58:50 +0000
committerChris McDonough <chrism@agendaless.com>2009-06-18 21:58:50 +0000
commit8b3f783c610668aa704b2d63e0a25ee6386cec20 (patch)
tree409abca7550cb9cdf32b1ac64f23b4604670297d /docs
parentf5c25ef97393f7b4bf1353b11eeb841c53e2feaf (diff)
downloadpyramid-8b3f783c610668aa704b2d63e0a25ee6386cec20.tar.gz
pyramid-8b3f783c610668aa704b2d63e0a25ee6386cec20.tar.bz2
pyramid-8b3f783c610668aa704b2d63e0a25ee6386cec20.zip
Document request-only calling convention.
Diffstat (limited to 'docs')
-rw-r--r--docs/narr/views.rst44
1 files changed, 42 insertions, 2 deletions
diff --git a/docs/narr/views.rst b/docs/narr/views.rst
index 6b8676386..296ed674f 100644
--- a/docs/narr/views.rst
+++ b/docs/narr/views.rst
@@ -30,8 +30,9 @@ function can be defined as follows:
context
- An instance of a model found via graph :term:`traversal` or
- :term:`URL dispatch`.
+ An instance of a :term:`context` found via graph :term:`traversal`
+ or :term:`URL dispatch`. If the context is found via traversal, it
+ will be a :term:`model` object.
request
@@ -78,6 +79,45 @@ For example:
The context and request objects passed to ``__init__`` are the same
types of objects as described in :ref:`function_as_view`.
+Alternate "Request-Only" View Argument Convention
+-------------------------------------------------
+
+Views may alternately be defined as callables that accept only a
+request object, instead of both a context and a request. The
+following types work as views in this style:
+
+#. Functions that accept a single argument ``request``, e.g.::
+
+ from webob import Response
+
+ def aview(request):
+ return Response('OK')
+
+#. New and old-style classes that have an ``__init__`` method that
+ accepts ``self, request``, e.g.::
+
+ from webob import Response
+
+ def View(object):
+ __init__(self, request):
+ return Response('OK')
+
+#. Arbitrary callables that have a ``__call__`` method that accepts
+ ``self, request``, e.g.::
+
+ from webob import Response
+
+ def AView(object):
+ def __call__(self, request):
+ return Response('OK')
+ view = AView()
+
+This style of calling convention is useful for :term:`url dispatch`
+based applications, where the context is seldom used within the view
+code itself. The view always has access to the context via
+``request.context`` in any case, so it's still available even if you
+use the request-only calling convention.
+
The Response
------------