diff options
| author | Michael Merickel <michael@merickel.org> | 2013-08-19 21:53:10 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2013-08-19 21:53:10 -0500 |
| commit | c14c8d7c86bd5cad207fab9acc053dc723dd2acf (patch) | |
| tree | 35dc7e54a4a739a0f5abf37f4e80c7f332c0b40c /docs | |
| parent | 4aec433291dc7b0c08d27fe6352ecf7585052e73 (diff) | |
| parent | a6aa55360986b008b086551ea7414d3bf6e054e9 (diff) | |
| download | pyramid-c14c8d7c86bd5cad207fab9acc053dc723dd2acf.tar.gz pyramid-c14c8d7c86bd5cad207fab9acc053dc723dd2acf.tar.bz2 pyramid-c14c8d7c86bd5cad207fab9acc053dc723dd2acf.zip | |
Merge branch 'feature.issue611-external-static-routes' of tomster/pyramid into feature.external-routes
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/narr/urldispatch.rst | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index 310c160c0..8f03b1080 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -105,6 +105,7 @@ to using the previous combination of ``add_route`` and ``add_view``. .. _route_pattern_syntax: + Route Pattern Syntax ~~~~~~~~~~~~~~~~~~~~ @@ -127,6 +128,10 @@ and: /{foo}/bar/baz +If a pattern is a valid URL it won't be ever matched against an incoming +request. Instead it can be useful for generating external URLs. See +:ref:`External routes <external_route_narr>` for details. + A pattern segment (an individual item between ``/`` characters in the pattern) may either be a literal string (e.g. ``foo``) *or* it may be a replacement marker (e.g. ``{foo}``) or a certain combination of both. A @@ -754,9 +759,43 @@ other non-``name`` and non-``pattern`` arguments to exception to this rule is use of the ``pregenerator`` argument, which is not ignored when ``static`` is ``True``. +:ref:`External routes <external_route_narr>` are implicitly static. + .. versionadded:: 1.1 the ``static`` argument to :meth:`~pyramid.config.Configurator.add_route` +.. _external_route_narr: + + +External Routes +--------------- + +.. versionadded:: 1.5 + +Route patterns that are valid URLs, are treated as external routes. Like +:ref:`static routes <static_route_narr>` they are useful for URL generation +purposes only and are never considered for matching at request time. + +.. code-block:: python + :linenos: + + >>> config = Configurator() + >>> config.add_route('youtube', 'https://youtube.com/watch/{video_id}') + ... + >>> request.route_url('youtube', video_id='oHg5SJYRHA0') + >>> "https://youtube.com/watch/oHg5SJYRHA0" + +All pattern replacements and calls to +:meth:`pyramid.request.Request.route_url` will work as expected. Note that +:meth:`pyramid.request.Request.route_path` will also just return the external +URLs path part. + +.. note:: + + The external URL feature is implemented with a :term:`pregenerator` so you + cannot use both with the same route. + + .. index:: single: redirecting to slash-appended routes |
