summaryrefslogtreecommitdiff
path: root/docs/narr/viewconfig.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/narr/viewconfig.rst')
-rw-r--r--docs/narr/viewconfig.rst67
1 files changed, 35 insertions, 32 deletions
diff --git a/docs/narr/viewconfig.rst b/docs/narr/viewconfig.rst
index e09fd83ab..7c76116f7 100644
--- a/docs/narr/viewconfig.rst
+++ b/docs/narr/viewconfig.rst
@@ -465,6 +465,36 @@ configured view.
.. versionadded:: 1.4a1
+Inverting Predicate Values
+++++++++++++++++++++++++++
+
+You can invert the meaning of any predicate value by wrapping it in a call to
+:class:`pyramid.config.not_`.
+
+.. code-block:: python
+ :linenos:
+
+ from pyramid.config import not_
+
+ config.add_view(
+ 'mypackage.views.my_view',
+ route_name='ok',
+ request_method=not_('POST')
+ )
+
+The above example will ensure that the view is called if the request method
+is *not* ``POST``, at least if no other view is more specific.
+
+This technique of wrapping a predicate value in ``not_`` can be used anywhere
+predicate values are accepted:
+
+- :meth:`pyramid.config.Configurator.add_view`
+
+- :meth:`pyramid.view.view_config`
+
+.. versionadded:: 1.5
+
+
.. index::
single: view_config decorator
@@ -557,35 +587,6 @@ form of :term:`declarative configuration`, while
:meth:`pyramid.config.Configurator.add_view` is a form of :term:`imperative
configuration`. However, they both do the same thing.
-Inverting Predicate Values
-~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-You can invert the meaning of any predicate value by wrapping it in a call to
-:class:`pyramid.config.not_`.
-
-.. code-block:: python
- :linenos:
-
- from pyramid.config import not_
-
- config.add_view(
- 'mypackage.views.my_view',
- route_name='ok',
- request_method=not_('POST')
- )
-
-The above example will ensure that the view is called if the request method
-is *not* ``POST``, at least if no other view is more specific.
-
-This technique of wrapping a predicate value in ``not_`` can be used anywhere
-predicate values are accepted:
-
-- :meth:`pyramid.config.Configurator.add_view`
-
-- :meth:`pyramid.view.view_config`
-
-.. versionadded:: 1.5
-
.. index::
single: view_config placement
@@ -821,7 +822,7 @@ of this:
def delete(self):
return Response('delete')
- if __name__ == '__main__':
+ def main(global_config, **settings):
config = Configurator()
config.add_route('rest', '/rest')
config.add_view(
@@ -830,9 +831,10 @@ of this:
RESTView, route_name='rest', attr='post', request_method='POST')
config.add_view(
RESTView, route_name='rest', attr='delete', request_method='DELETE')
+ return config.make_wsgi_app()
To reduce the amount of repetition in the ``config.add_view`` statements, we
-can move the ``route_name='rest'`` argument to a ``@view_default`` class
+can move the ``route_name='rest'`` argument to a ``@view_defaults`` class
decorator on the RESTView class:
.. code-block:: python
@@ -856,12 +858,13 @@ decorator on the RESTView class:
def delete(self):
return Response('delete')
- if __name__ == '__main__':
+ def main(global_config, **settings):
config = Configurator()
config.add_route('rest', '/rest')
config.add_view(RESTView, attr='get', request_method='GET')
config.add_view(RESTView, attr='post', request_method='POST')
config.add_view(RESTView, attr='delete', request_method='DELETE')
+ return config.make_wsgi_app()
:class:`pyramid.view.view_defaults` accepts the same set of arguments that
:class:`pyramid.view.view_config` does, and they have the same meaning. Each