summaryrefslogtreecommitdiff
path: root/docs/narr
diff options
context:
space:
mode:
authorMichael Merickel <github@m.merickel.org>2018-11-12 20:07:15 -0600
committerGitHub <noreply@github.com>2018-11-12 20:07:15 -0600
commit7429fcb5a96aa10bbe86da08bd0b30c9292efdde (patch)
tree548defadbf50447b4e6a0b1f9363f3d08ded8bfc /docs/narr
parent420ea05bee3ad376c4369f401b2696b31312c5e1 (diff)
parent2d32ae81abc473fb21b4bc42aec479c656693f1c (diff)
downloadpyramid-7429fcb5a96aa10bbe86da08bd0b30c9292efdde.tar.gz
pyramid-7429fcb5a96aa10bbe86da08bd0b30c9292efdde.tar.bz2
pyramid-7429fcb5a96aa10bbe86da08bd0b30c9292efdde.zip
Merge pull request #3420 from mmerickel/bare-route-prefix-2
support inherit_slash=True on add_route
Diffstat (limited to 'docs/narr')
-rw-r--r--docs/narr/urldispatch.rst18
1 files changed, 17 insertions, 1 deletions
diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst
index 52d64891c..3b737b46d 100644
--- a/docs/narr/urldispatch.rst
+++ b/docs/narr/urldispatch.rst
@@ -971,7 +971,7 @@ application from small and potentially reusable components.
The :meth:`pyramid.config.Configurator.include` method accepts an argument
named ``route_prefix`` which can be useful to authors of URL-dispatch-based
applications. If ``route_prefix`` is supplied to the include method, it must
-be a string. This string represents a route prefix that will be prepended to
+be a string. This string represents a :term:`route prefix` that will be prepended to
all route patterns added by the *included* configuration. Any calls to
:meth:`pyramid.config.Configurator.add_route` within the included callable will
have their pattern prefixed with the value of ``route_prefix``. This can be
@@ -998,6 +998,22 @@ then only match if the URL path is ``/users/show``, and when the
:meth:`pyramid.request.Request.route_url` function is called with the route
name ``show_users``, it will generate a URL with that same path.
+To create a route that matches requests to the ``route_prefix`` without a trailing slash, pass ``inherit_slash=True`` to the call to ``add_route``.
+
+.. code-block:: python
+ :linenos:
+
+ from pyramid.config import Configurator
+
+ def users_include(config):
+ config.add_route('show_users', '', inherit_slash=True)
+
+ def main(global_config, **settings):
+ config = Configurator()
+ config.include(users_include, route_prefix='/users')
+
+The above configuration will match ``/users`` instead of ``/users/``.
+
Route prefixes are recursive, so if a callable executed via an include itself
turns around and includes another callable, the second-level route prefix will
be prepended with the first: