From 27ae86b27d2ea8956210a12c7564e07b3f6101ff Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 30 Sep 2009 05:23:02 +0000 Subject: - Describe "request-only" view calling conventions inside the urldispatch narrative chapter, where it's most helpful. --- CHANGES.txt | 3 +++ docs/narr/urldispatch.rst | 23 +++++++++++++++++++++++ docs/narr/views.rst | 2 ++ 3 files changed, 28 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 8a82bc086..9ead6e65e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,9 @@ Documentation - An ``exceptions`` API chapter was added, documenting the new ``repoze.bfg.exceptions`` module. +- Describe "request-only" view calling conventions inside the + urldispatch narrative chapter, where it's most helpful. + Features -------- diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index a8d50f9e2..a43d5e125 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -349,6 +349,29 @@ type of object created for a context when there is no "factory" specified in the ``route`` declaration. It is a mapping object, a lot like a dictionary. +When using :term:`url dispatch` exclusively in an application (as +opposed to using both url dispatch and :term:`traversal`), the +*context* of the view isn't terribly interesting most of the time, +particularly if you never use a ``factory`` attribute on your route +definitions. For this reason, :mod:`repoze.bfg` supports view +callables defined with only a ``request`` argument in their argument +specification. For example, the below view statement is competely +equivalent to the above view statement: + +.. code-block:: python + :linenos: + + from webob import Response + + def hello_view(request): + return Response('Hello!') + +Even if you use the request-only argument format in view callables, +you can still get to the ``context`` of the view (if necessary) by +accessing ``request.context``. + +See also: :ref:`request_only_view_definitions`. + Example 2 ~~~~~~~~~ diff --git a/docs/narr/views.rst b/docs/narr/views.rst index b45221e71..53fedbedc 100644 --- a/docs/narr/views.rst +++ b/docs/narr/views.rst @@ -82,6 +82,8 @@ represent the method expected to return a response, you can use an ``attr`` value as part of view configuration. See :ref:`view_configuration`. +.. _request_only_view_definitions: + Request-Only View Definitions ----------------------------- -- cgit v1.2.3