summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rwxr-xr-xdocs/convert_images.sh2
-rw-r--r--docs/narr/configuration.rst9
-rw-r--r--docs/narr/contextfinding.rst13
-rw-r--r--docs/narr/firstapp.rst10
-rw-r--r--docs/narr/hybrid.rst72
-rw-r--r--docs/narr/install.rst1
-rw-r--r--docs/narr/project.rst13
-rw-r--r--docs/narr/traversal.rst2
-rw-r--r--docs/narr/urldispatch.rst84
9 files changed, 115 insertions, 91 deletions
diff --git a/docs/convert_images.sh b/docs/convert_images.sh
index 3bd22c01b..29539c6b5 100755
--- a/docs/convert_images.sh
+++ b/docs/convert_images.sh
@@ -1,4 +1,4 @@
-TEXDIR=.build/latex
+TEXDIR=_build/latex
if test ! -z $BOOK; then
for img in $TEXDIR/*.png;
diff --git a/docs/narr/configuration.rst b/docs/narr/configuration.rst
index ae02a5a6c..d55a190e2 100644
--- a/docs/narr/configuration.rst
+++ b/docs/narr/configuration.rst
@@ -10,9 +10,9 @@ Each deployment of an application written using :app:`Pyramid` implies a
specific *configuration* of the framework itself. For example, an
application which serves up MP3s for user consumption might plug code into
the framework that manages songs, while an application that manages corporate
-data might plug in code that manages accounting information. :app:`Pyramid`
-refers to the way in which code is plugged in to it for a specific
-application as "configuration".
+data might plug in code that manages accounting information. The way in which
+code is plugged in to :app:`Pyramid`, for a specific application, is referred
+to as "configuration".
Most people understand "configuration" as coarse settings that inform the
high-level operation of a specific application deployment. For instance,
@@ -21,8 +21,7 @@ application startup time as "configuration". :app:`Pyramid` extends this
pattern to application development, using the term "configuration" to express
standardized ways that code gets plugged into a deployment of the framework
itself. When you plug code into the :app:`Pyramid` framework, you are
-"configuring" :app:`Pyramid` for the purpose of creating a particular
-application deployment.
+"configuring" :app:`Pyramid` to create a particular application.
.. index::
single: imperative configuration
diff --git a/docs/narr/contextfinding.rst b/docs/narr/contextfinding.rst
index 770f97d15..691ad7b8e 100644
--- a/docs/narr/contextfinding.rst
+++ b/docs/narr/contextfinding.rst
@@ -51,16 +51,15 @@ requesting user.
that do not provide a notion of a context.
There are two separate :term:`context finding` subsystems in
-:app:`Pyramid`: :term:`traversal` and :term:`URL dispatch`. The
-subsystems are documented within this chapter. They can be used
-separately or they can be combined. Three chapters which follow
-describe :term:`context finding`: :ref:`traversal_chapter`,
+:app:`Pyramid`: :term:`traversal` and :term:`URL dispatch`. They can
+be used separately or they can be combined. Three chapters which
+follow describe :term:`context finding`: :ref:`traversal_chapter`,
:ref:`urldispatch_chapter` and :ref:`hybrid_chapter`.
There is only one :term:`view lookup` subsystem present in
-:app:`Pyramid`. Where appropriate, within this chapter, we
-describe how view lookup interacts with context finding. One chapter
-which follows describes :term:`view lookup`: :ref:`views_chapter`.
+:app:`Pyramid`. Where appropriate, we will describe how view lookup
+interacts with context finding. One chapter which follows describes
+:term:`view lookup`: :ref:`views_chapter`.
Should I Use Traversal or URL Dispatch for Context Finding?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/narr/firstapp.rst b/docs/narr/firstapp.rst
index 9d3cad13c..8835f395a 100644
--- a/docs/narr/firstapp.rst
+++ b/docs/narr/firstapp.rst
@@ -137,10 +137,10 @@ passed to the ``Response`` constructor as the *body* of the response. In the
Application Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~
-In the above script, the following code, representing the
-*configuration* of an application which uses the previously defined
-imports and function definitions is placed within the confines of an
-``if`` statement:
+In the above script, the following code represents the *configuration* of this
+simple application. The application is configured using the previously defined
+imports and function definitions, placed within the confines of an ``if``
+statement:
.. code-block:: python
:linenos:
@@ -242,7 +242,7 @@ circumstances which would cause the view configuration's callable to
be invoked. In general, a greater number of predicates supplied along
with a view configuration will more strictly limit the applicability
of its associated view callable. When :app:`Pyramid` processes a
-request, however, the view callable with the *most specific* view
+request, the view callable with the *most specific* view
configuration (the view configuration that matches the most specific
set of predicates) is always invoked.
diff --git a/docs/narr/hybrid.rst b/docs/narr/hybrid.rst
index e704463c7..a6b1eb217 100644
--- a/docs/narr/hybrid.rst
+++ b/docs/narr/hybrid.rst
@@ -102,7 +102,7 @@ application and a hybrid application:
hybrid application, at least one route will be defined.
- In a purely traversal based application, the root object used is
- global implied by the :term:`root factory` provided at startup
+ global, implied by the :term:`root factory` provided at startup
time; in a hybrid application, the :term:`root` object at which
traversal begins may be varied on a per-route basis.
@@ -207,16 +207,20 @@ the matched route's configuration.
Because the pattern of the above route ends with ``*traverse``, when this
route configuration is matched during a request, :app:`Pyramid`
will attempt to use :term:`traversal` against the :term:`root` object
-implied by the :term:`root factory` implied by the route's
-configuration. Once :term:`traversal` has found a :term:`context`,
+implied by the :term:`root factory` that is implied by the route's
+configuration. Since no ``root_factory`` argument is explicitly specified
+for this route, this will either be the *global* root factory
+for the application, or the *default* root factory.
+Once :term:`traversal` has found a :term:`context`,
:term:`view lookup` will be invoked in almost exactly the same way it
would have been invoked in a "pure" traversal-based application.
-The *default* :term:`root factory` cannot be traversed: it has no
-useful ``__getitem__`` method. So we'll need to associate this route
-configuration with a non-default root factory in order to create a
-useful hybrid application. To that end, let's imagine that we've
-created a root factory that looks like so in a module named
+Let's assume there is no *global* :term:`root factory` configured in
+this application. The *default* :term:`root factory` cannot be traversed:
+it has no useful ``__getitem__`` method. So we'll need to associate
+this route configuration with a custom root factory in order to
+create a useful hybrid application. To that end, let's imagine that
+we've created a root factory that looks like so in a module named
``routes.py``:
.. code-block:: python
@@ -236,7 +240,7 @@ created a root factory that looks like so in a module named
def root_factory(request):
return root
-Above, we've defined a (bogus) graph here that can be traversed, and a
+Above, we've defined a (bogus) graph that can be traversed, and a
``root_factory`` function that can be used as part of a particular
route configuration statement:
@@ -246,20 +250,20 @@ route configuration statement:
config.add_route('home', '{foo}/{bar}/*traverse',
factory='mypackage.routes.root_factory')
-The ``factory`` above points at the function we've defined. It
-will return an instance of the ``Traversable`` class as a root object
-whenever this route is matched. Because the ``Traversable`` object
-we've defined has a ``__getitem__`` method that does something
-nominally useful, and because traversal uses ``__getitem__`` to walk
-the nodes that make up an object graph, using traversal against the
-root object implied by our route statement becomes a reasonable thing
-to do.
+The ``factory`` above points at the function we've defined. It will
+return an instance of the ``Traversable`` class as a root object
+whenever this route is matched. Instances of the``Traversable`` class
+can be used for graph traversal because they have a ``__getitem__``
+method that does something nominally useful. Since traversal uses
+``__getitem__`` to walk the nodes of an object graph, using traversal
+against the root object implied by our route statement is a reasonable
+thing to do.
.. note::
We could have also used our ``root_factory`` callable as the
``root_factory`` argument of the
- :class:`pyramid.configuration.Configurator` constructor instead
+ :class:`pyramid.configuration.Configurator` constructor, instead
of associating it with a particular route inside the route's
configuration. Every hybrid route configuration that is matched but
which does *not* name a ``factory``` attribute will use the use
@@ -308,7 +312,7 @@ route's name, in order to indicate that the view should *only be invoked when
the route matches*.
Calls to :meth:`pyramid.configuration.Configurator.add_view` may pass a
-``route_name`` attribute which refers to the value of an existing route's
+``route_name`` attribute, which refers to the value of an existing route's
``name`` argument. In the above example, the route name is ``home``,
referring to the name of the route defined above it.
@@ -385,7 +389,7 @@ request comes in that causes the route to match in such a way that the
This means that the root object's ``__getitem__`` will be called with
the name ``1`` during the traversal phase. If the ``1`` object
exists, it will become the :term:`context` of the request.
-:ref:`traversal_chapter` has more information about traversal.
+The :ref:`traversal_chapter` chapter has more information about traversal.
If the traversal path contains segment marker names which are not
present in the pattern argument, a runtime error will occur. The
@@ -402,14 +406,15 @@ with this route).
Making Global Views Match
+++++++++++++++++++++++++
-By default, view configurations that don't mention a ``route_name`` will be
-not found by view lookup when a route that mentions a ``*traverse`` in its
-pattern matches. You can make these match forcibly by adding the
-``use_global_views`` flag to the route definition. For example, the
-``myproject.views.bazbuz`` view below will be found if the route named
-``abc`` below is matched and the ``PATH_INFO`` is ``/abc/bazbuz``, even
-though the view configuration statement does not have the
-``route_name="abc"`` attribute.
+By default, only view configurations that mention a ``route_name``
+will be found during view lookup when a route that has a ``*traverse``
+in its pattern matches. You can allow views without a ``route_name``
+attribute to match a route by adding the ``use_global_views`` flag to
+the route definition. For example, the ``myproject.views.bazbuz``
+view below will be found if the route named ``abc`` below is matched
+and the ``PATH_INFO`` is ``/abc/bazbuz``, even though the view
+configuration statement does not have the ``route_name="abc"``
+attribute.
.. code-block:: python
:linenos:
@@ -493,10 +498,10 @@ Can also be spelled like so:
The two spellings are logically equivalent. In fact, the former is
just a syntactical shortcut for the latter.
-Binding Extra Views Against a Route Configuration that Doesn't Have a ``*traverse`` Element In Its Patttern
+Binding Extra Views Against a Route Configuration that Doesn't Have a ``*traverse`` Element In Its Pattern
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Here's another corner case that just makes no sense.
+Here's another corner case that just makes no sense:
.. code-block:: python
:linenos:
@@ -511,7 +516,7 @@ itself (``myproject.views.abc``) will ever be invoked when the route matches,
because the default view is always invoked when a route matches and when no
post-match traversal is performed.
-To make the above view declaration non-useless, the special ``*traverse``
+To make the above view declaration useful, the special ``*traverse``
token must end the route's pattern. For example:
.. code-block:: python
@@ -521,3 +526,8 @@ token must end the route's pattern. For example:
config.add_view('myproject.views.bazbuz', name='bazbuz',
route_name='abc')
+With the above configuration, the ``myproject.views.bazbuz`` view will
+be invoked when the request URI is ``/abc/bazbuz``, assuming there is
+no object contained by the root object with the key ``bazbuz``. A
+different request URI, such as ``/abc/foo/bar``, would invoke the
+default ``myproject.views.abc`` view.
diff --git a/docs/narr/install.rst b/docs/narr/install.rst
index c753b7298..5a8d7e459 100644
--- a/docs/narr/install.rst
+++ b/docs/narr/install.rst
@@ -86,7 +86,6 @@ the following commands:
[chrism@vitaminf ~]$ mkdir tmp
[chrism@vitaminf ~]$ mkdir opt
[chrism@vitaminf ~]$ cd tmp
- [chrism@vitaminf tmp]$ cd tmp
[chrism@vitaminf tmp]$ wget \
http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz
[chrism@vitaminf tmp]$ tar xvzf Python-2.6.4.tgz
diff --git a/docs/narr/project.rst b/docs/narr/project.rst
index 1758e9d00..c676917b4 100644
--- a/docs/narr/project.rst
+++ b/docs/narr/project.rst
@@ -145,6 +145,17 @@ project we name ``MyProject``:
name during ``paster create`` by adding the project name to the
command line, e.g. ``paster create -t pyramid_starter MyProject``.
+.. note:: You may encounter an error when using ``paster create``
+ if a dependent Python package is not installed. This will
+ result in a traceback ending in:
+
+ .. code-block:: text
+
+ pkg_resources.DistributionNotFound: <package name>
+
+ Simply run ``bin/easy_install``, with the missing package
+ name from the error message, to workaround this issue.
+
As a result of invoking the ``paster create`` command, a project is
created in a directory named ``MyProject``. That directory is a
:term:`setuptools` :term:`project` directory from which a setuptools
@@ -760,7 +771,7 @@ also informs Python that the directory which contains it is a *package*.
:term:`context` of the request is an instance of the
:class:`myproject.models.MyModel` class. The first argument to
``add_view`` points at a Python function that does all the work for this
- view, also known as a :term:`view callable` via a :term:`dotted Python
+ view, also known as a :term:`view callable`, via a :term:`dotted Python
name`. The view declaration also names a ``renderer``, which in this case
is a template that will be used to render the result of the view callable.
This particular view declaration points at
diff --git a/docs/narr/traversal.rst b/docs/narr/traversal.rst
index 56594ed5a..67296d21a 100644
--- a/docs/narr/traversal.rst
+++ b/docs/narr/traversal.rst
@@ -360,7 +360,7 @@ and a :term:`view name`.
of path segments that come from ``PATH_INFO`` that are "left over"
after traversal has completed.
-Once :term:`context` and :term:`view name` and associated attributes
+Once :term:`context`, :term:`view name`, and associated attributes
such as the :term:`subpath` are located, the job of :term:`traversal`
is finished. It passes back the information it obtained to its
caller, the :app:`Pyramid` :term:`Router`, which subsequently
diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst
index df7d592f9..1b911a4a8 100644
--- a/docs/narr/urldispatch.rst
+++ b/docs/narr/urldispatch.rst
@@ -96,7 +96,7 @@ registry`. Here's an example:
.. versionchanged:: 1.0a4
Prior to 1.0a4, routes allow for a marker starting with a ``:``, for
- example ``/prefix/{one}``. Starting in 1.0a4, this style is deprecated
+ example ``/prefix/:one/:two``. Starting in 1.0a4, this style is deprecated
in favor or ``{}`` usage which allows for additional functionality.
.. index::
@@ -179,12 +179,12 @@ during a request. To do so:
to service requests that match the route pattern.
In this way, we supply a shortcut to the developer. Under the hood,
-:app:`Pyramid` still consumes the :term:`context finding` and
-:term:`view lookup` subsystems provided by :app:`Pyramid`, but in a
-way which does not require that a developer understand either of them
-if he doesn't want or need to. It also means that we can allow a
-developer to combine :term:`URL dispatch` and :term:`traversal` in
-various exceptional cases as documented in :ref:`hybrid_chapter`.
+the :term:`context finding` and :term:`view lookup` subsystems
+provided by :app:`Pyramid` are still being utilized, but in a way
+which does not require a developer to understand either of them in
+detail. It also means that we can allow a developer to combine
+:term:`URL dispatch` and :term:`traversal` in various exceptional
+cases as documented in :ref:`hybrid_chapter`.
.. index::
single: route path pattern syntax
@@ -263,15 +263,15 @@ To capture both segments, two replacement markers can be used:
foo/{name}.{ext}
-The literal path ``/foo/biz.html`` will match the above route pattern, and the
-match result will be ``{'name': 'biz', 'ext': 'html'}``. This occurs because
-the replacement marker ``{name}`` has a literal part of ``.`` between the other
-replacement marker ``:ext``.
+The literal path ``/foo/biz.html`` will match the above route pattern,
+and the match result will be ``{'name': 'biz', 'ext': 'html'}``. This
+occurs because the replacement marker ``{name}`` has a literal part of
+``.`` (period) between the other replacement marker ``{ext}``.
-It is possible to use two replacement markers without any literal characters
-between them, for instance ``/{foo}{bar}``. This would be a nonsensical pattern
-without specifying a custom regular expression to restrict what a marker
-captures.
+It is possible to use two replacement markers without any literal
+characters between them, for instance ``/{foo}{bar}``. However, this
+would be a nonsensical pattern without specifying a custom regular
+expression to restrict what each marker captures.
Segments must contain at least one character in order to match a
segment replacement marker. For example, for the URL ``/abc/``:
@@ -281,7 +281,7 @@ segment replacement marker. For example, for the URL ``/abc/``:
- ``/{foo}/`` will match.
Note that values representing path segments matched with a
-``:segment`` match will be url-unquoted and decoded from UTF-8 into
+``{segment}`` match will be url-unquoted and decoded from UTF-8 into
Unicode within the matchdict. So for instance, the following
pattern:
@@ -356,7 +356,7 @@ matchdicts::
foo/abc/def/a/b/c -> {'baz':'abc', 'bar':'def', 'fizzle': 'a/b/c')}
This occurs because the default regular expression for a marker is ``[^/]+``
-which will match everything up to the first ``/``, while ``{filzzle:.*}`` will
+which will match everything up to the first ``/``, while ``{fizzle:.*}`` will
result in a regular expression match of ``.*`` capturing the remainder into
a single value.
@@ -366,9 +366,9 @@ a single value.
Route Declaration Ordering
~~~~~~~~~~~~~~~~~~~~~~~~~~
-Because route configuration declarations are evaluated in a specific
-order when a request enters the system, route configuration
-declaration ordering is very important.
+Route configuration declarations are evaluated in a specific
+order when a request enters the system. As a result, the
+order of route configuration declarations is very important.
The order that routes declarations are evaluated is the order in which
they are added to the application at startup time. This is unlike
@@ -388,7 +388,7 @@ be added in the following order:
members/abc
In such a configuration, the ``members/abc`` pattern would *never* be
-matched; this is because the match ordering will always match
+matched. This is because the match ordering will always match
``members/{def}`` first; the route configuration with ``members/abc``
will never be evaluated.
@@ -415,7 +415,7 @@ found via :term:`view lookup`.
factory='myproject.models.root_factory')
The factory can either be a Python object or a :term:`dotted Python name` (a
-string) which points to such a Python oject, as it is above.
+string) which points to such a Python object, as it is above.
In this way, each route can use a different factory, making it
possible to supply a different :term:`context` object to the view
@@ -423,8 +423,8 @@ related to each particular route.
Supplying a different context for each route is useful when you're
trying to use a :app:`Pyramid` :term:`authorization policy` to
-provide declarative "context-sensitive" security checks; each context
-can maintain a separate :term:`ACL`, as in
+provide declarative, "context sensitive" security checks; each context
+can maintain a separate :term:`ACL`, as documented in
:ref:`using_security_with_urldispatch`. It is also useful when you
wish to combine URL dispatch with :term:`traversal` as documented
within :ref:`hybrid_chapter`.
@@ -1073,12 +1073,14 @@ Redirecting to Slash-Appended Routes
------------------------------------
For behavior like Django's ``APPEND_SLASH=True``, use the
-:func:`pyramid.view.append_slash_notfound_view` view as the
-:term:`Not Found view` in your application. When this view is the Not
-Found view (indicating that no view was found), and any routes have
-been defined in the configuration of your application, if the value of
-``PATH_INFO`` does not already end in a slash, and if the value of
-``PATH_INFO`` *plus* a slash matches any route's pattern, it does an
+:func:`pyramid.view.append_slash_notfound_view` view as the :term:`Not
+Found view` in your application. Defining this view as the :term:`Not
+Found view` is a way to automatically redirect requests where the URL
+lacks a trailing slash, but requires one to match the proper route.
+When configured, along with at least one other route in your
+application, this view will be invoked if the value of ``PATH_INFO``
+does not already end in a slash, and if the value of ``PATH_INFO``
+*plus* a slash matches any route's pattern. In this case it does an
HTTP redirect to the slash-appended ``PATH_INFO``.
Let's use an example, because this behavior is a bit magical. If the
@@ -1091,20 +1093,24 @@ your route configuration looks like so:
config.add_route('noslash', 'no_slash', view='myproject.views.no_slash')
config.add_route('hasslash', 'has_slash/', view='myproject.views.has_slash')
+If a request enters the application with the ``PATH_INFO``
+value of ``/has_slash/``, the second route will match. If a request
+enters the application with the ``PATH_INFO`` value of ``/has_slash``,
+a route *will* be found by the slash-appending not found view. An HTTP
+redirect to ``/has_slash/`` will be returned to the user's browser.
+
If a request enters the application with the ``PATH_INFO`` value of
-``/no_slash``, the first route will match. If a request enters the
+``/no_slash``, the first route will match. However, if a request enters the
application with the ``PATH_INFO`` value of ``/no_slash/``, *no* route
-will match, and the slash-appending "not found" view will *not* find a
+will match, and the slash-appending not found view will *not* find a
matching route with an appended slash.
-However, if a request enters the application with the ``PATH_INFO``
-value of ``/has_slash/``, the second route will match. If a request
-enters the application with the ``PATH_INFO`` value of ``/has_slash``,
-a route *will* be found by the slash appending notfound view. An HTTP
-redirect to ``/has_slash/`` will be returned to the user's browser.
+.. warning::
-Note that this will *lose* ``POST`` data information (turning it into
-a GET), so you shouldn't rely on this to redirect POST requests.
+ You **should not** rely on this mechanism to redirect ``POST`` requests.
+ The redirect of the slash-appending not found view will turn a ``POST``
+ request into a ``GET``, losing any ``POST`` data in the original
+ request.
To configure the slash-appending not found view in your application, change
the application's startup configuration, adding the following stanza: