summaryrefslogtreecommitdiff
path: root/docs/tutorials/wiki2/basiclayout.rst
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2016-02-14 17:40:03 -0600
committerMichael Merickel <michael@merickel.org>2016-02-14 17:47:33 -0600
commitda5ebc28c38ea32ad99389b5bc23e2f847af8047 (patch)
treef72f10731087311cc3ec47af7084ad2946beb82c /docs/tutorials/wiki2/basiclayout.rst
parent42c93166fbe676341b1d94ec3659ae772dd073d8 (diff)
downloadpyramid-da5ebc28c38ea32ad99389b5bc23e2f847af8047.tar.gz
pyramid-da5ebc28c38ea32ad99389b5bc23e2f847af8047.tar.bz2
pyramid-da5ebc28c38ea32ad99389b5bc23e2f847af8047.zip
split routes into a separate module
Diffstat (limited to 'docs/tutorials/wiki2/basiclayout.rst')
-rw-r--r--docs/tutorials/wiki2/basiclayout.rst64
1 files changed, 39 insertions, 25 deletions
diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst
index 485d38047..1ae51eb93 100644
--- a/docs/tutorials/wiki2/basiclayout.rst
+++ b/docs/tutorials/wiki2/basiclayout.rst
@@ -74,35 +74,19 @@ exact setup of the models will be covered later.
:lineno-match:
:language: py
-``main`` now calls :meth:`pyramid.config.Configurator.add_static_view` with
-two arguments: ``static`` (the name), and ``static`` (the path):
+Next include the ``routes`` module using a dotted Python path. This module
+will be explained in the next section.
.. literalinclude:: src/basiclayout/tutorial/__init__.py
:lines: 10
:lineno-match:
:language: py
-This registers a static resource view which will match any URL that starts
-with the prefix ``/static`` (by virtue of the first argument to
-``add_static_view``). This will serve up static resources for us from within
-the ``static`` directory of our ``tutorial`` package, in this case, via
-``http://localhost:6543/static/`` and below (by virtue of the second argument
-to ``add_static_view``). With this declaration, we're saying that any URL that
-starts with ``/static`` should go to the static view; any remainder of its
-path (e.g. the ``/foo`` in ``/static/foo``) will be used to compose a path to
-a static file resource, such as a CSS file.
-
-Using the configurator ``main`` also registers a :term:`route configuration`
-via the :meth:`pyramid.config.Configurator.add_route` method that will be
-used when the URL is ``/``:
-
-.. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 11
- :lineno-match:
- :language: py
+.. note::
-Since this route has a ``pattern`` equaling ``/``, it is the route that will
-be matched when the URL ``/`` is visited, e.g., ``http://localhost:6543/``.
+ Pyramid's :meth:`pyramid.config.Configurator.include` method is the
+ primary mechanism for extending the configurator and breaking your code
+ into feature-focused modules.
``main`` next calls the ``scan`` method of the configurator
(:meth:`pyramid.config.Configurator.scan`), which will recursively scan our
@@ -112,7 +96,7 @@ view configuration will be registered, which will allow one of our
application URLs to be mapped to some code.
.. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 12
+ :lines: 11
:lineno-match:
:language: py
@@ -121,11 +105,41 @@ Finally ``main`` is finished configuring things, so it uses the
:term:`WSGI` application:
.. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 13
- :lineno-start: 13
+ :lines: 12
+ :lineno-match:
:language: py
+Route declarations
+------------------
+
+Open the ``tutorials/routes.py`` file. It should already contain the
+following:
+
+.. literalinclude:: src/basiclayout/tutorial/routes.py
+ :linenos:
+ :language: py
+
+First, on line 2, call :meth:`pyramid.config.Configurator.add_static_view`
+with two arguments: ``static`` (the name), and ``static`` (the path).
+
+This registers a static resource view which will match any URL that starts
+with the prefix ``/static`` (by virtue of the first argument to
+``add_static_view``). This will serve up static resources for us from within
+the ``static`` directory of our ``tutorial`` package, in this case, via
+``http://localhost:6543/static/`` and below (by virtue of the second argument
+to ``add_static_view``). With this declaration, we're saying that any URL that
+starts with ``/static`` should go to the static view; any remainder of its
+path (e.g. the ``/foo`` in ``/static/foo``) will be used to compose a path to
+a static file resource, such as a CSS file.
+
+Second, on line 3, the module registers a :term:`route configuration`
+via the :meth:`pyramid.config.Configurator.add_route` method that will be
+used when the URL is ``/``. Since this route has a ``pattern`` equaling
+``/``, it is the route that will be matched when the URL ``/`` is visited,
+e.g., ``http://localhost:6543/``.
+
+
View declarations via the ``views`` package
-------------------------------------------