summaryrefslogtreecommitdiff
path: root/docs/tutorials/wiki2/basiclayout.rst
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2015-11-12 12:56:27 -0600
committerMichael Merickel <michael@merickel.org>2015-11-12 12:56:46 -0600
commit414b67b45bab156b9738105e180908c4eee8600a (patch)
tree6a9ee22d939c88f35786da0f06ff32b98102e374 /docs/tutorials/wiki2/basiclayout.rst
parentb4c96d2892d8271b300b1920e3ce5d2c0eae588b (diff)
downloadpyramid-414b67b45bab156b9738105e180908c4eee8600a.tar.gz
pyramid-414b67b45bab156b9738105e180908c4eee8600a.tar.bz2
pyramid-414b67b45bab156b9738105e180908c4eee8600a.zip
Restore progress after backing changes out of master.
This reverts commit 049e670aef9ea5611561546fd5c0e2dd6152b9b7.
Diffstat (limited to 'docs/tutorials/wiki2/basiclayout.rst')
-rw-r--r--docs/tutorials/wiki2/basiclayout.rst98
1 files changed, 55 insertions, 43 deletions
diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst
index 649c11e85..abe9e4202 100644
--- a/docs/tutorials/wiki2/basiclayout.rst
+++ b/docs/tutorials/wiki2/basiclayout.rst
@@ -12,12 +12,12 @@ Application configuration with ``__init__.py``
A directory on disk can be turned into a Python :term:`package` by containing
an ``__init__.py`` file. Even if empty, this marks a directory as a Python
-package. We use ``__init__.py`` both as a marker, indicating the directory
-in which it's contained is a package, and to contain application configuration
+package. We use ``__init__.py`` both as a marker, indicating the directory in
+which it's contained is a package, and to contain application configuration
code.
-Open ``tutorial/tutorial/__init__.py``. It should already contain
-the following:
+Open ``tutorial/tutorial/__init__.py``. It should already contain the
+following:
.. literalinclude:: src/basiclayout/tutorial/__init__.py
:linenos:
@@ -43,58 +43,37 @@ When you invoke the ``pserve development.ini`` command, the ``main`` function
above is executed. It accepts some settings and returns a :term:`WSGI`
application. (See :ref:`startup_chapter` for more about ``pserve``.)
-The main function first creates a :term:`SQLAlchemy` database engine using
-:func:`sqlalchemy.engine_from_config` from the ``sqlalchemy.`` prefixed
-settings in the ``development.ini`` file's ``[app:main]`` section.
-This will be a URI (something like ``sqlite://``):
-
- .. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 13
- :language: py
-
-``main`` then initializes our SQLAlchemy session object, passing it the
-engine:
-
- .. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 14
- :language: py
-
-``main`` subsequently initializes our SQLAlchemy declarative ``Base`` object,
-assigning the engine we created to the ``bind`` attribute of it's
-``metadata`` object. This allows table definitions done imperatively
-(instead of declaratively, via a class statement) to work. We won't use any
-such tables in our application, but if you add one later, long after you've
-forgotten about this tutorial, you won't be left scratching your head when it
-doesn't work.
-
- .. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 15
- :language: py
-
The next step of ``main`` is to construct a :term:`Configurator` object:
.. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 16
+ :lines: 7
:language: py
``settings`` is passed to the Configurator as a keyword argument with the
dictionary values passed as the ``**settings`` argument. This will be a
dictionary of settings parsed from the ``.ini`` file, which contains
deployment-related values such as ``pyramid.reload_templates``,
-``db_string``, etc.
+``sqlalchemy.url``, and so on.
-Next, include :term:`Chameleon` templating bindings so that we can use
-renderers with the ``.pt`` extension within our project.
+Next include :term:`Jinja2` templating bindings so that we can use renderers
+with the ``.jinja2`` extension within our project.
.. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 17
+ :lines: 8
+ :language: py
+
+Next include the module ``meta`` from the package ``models`` using a dotted
+Python path.
+
+ .. literalinclude:: src/basiclayout/tutorial/__init__.py
+ :lines: 9
:language: py
``main`` now calls :meth:`pyramid.config.Configurator.add_static_view` with
two arguments: ``static`` (the name), and ``static`` (the path):
.. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 18
+ :lines: 10
:language: py
This registers a static resource view which will match any URL that starts
@@ -112,11 +91,11 @@ via the :meth:`pyramid.config.Configurator.add_route` method that will be
used when the URL is ``/``:
.. literalinclude:: src/basiclayout/tutorial/__init__.py
- :lines: 19
+ :lines: 11
:language: py
-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/``.
+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/``.
``main`` next calls the ``scan`` method of the configurator
(:meth:`pyramid.config.Configurator.scan`), which will recursively scan our
@@ -126,10 +105,10 @@ 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: 20
+ :lines: 12
:language: py
-Finally, ``main`` is finished configuring things, so it uses the
+Finally ``main`` is finished configuring things, so it uses the
:meth:`pyramid.config.Configurator.make_wsgi_app` method to return a
:term:`WSGI` application:
@@ -187,6 +166,39 @@ to inform the user about possible actions to take to solve the problem.
Content models with the ``models`` package
------------------------------------------
+.. START moved from Application configuration with ``__init__.py``. This
+ section is a WIP, and needs to be updated using the new models package.
+
+The main function first creates a :term:`SQLAlchemy` database engine using
+:func:`sqlalchemy.engine_from_config` from the ``sqlalchemy.`` prefixed
+settings in the ``development.ini`` file's ``[app:main]`` section.
+This will be a URI (something like ``sqlite://``):
+
+ .. literalinclude:: src/basiclayout/tutorial/__init__.py
+ :lines: 13
+ :language: py
+
+``main`` then initializes our SQLAlchemy session object, passing it the
+engine:
+
+ .. literalinclude:: src/basiclayout/tutorial/__init__.py
+ :lines: 14
+ :language: py
+
+``main`` subsequently initializes our SQLAlchemy declarative ``Base`` object,
+assigning the engine we created to the ``bind`` attribute of it's
+``metadata`` object. This allows table definitions done imperatively
+(instead of declaratively, via a class statement) to work. We won't use any
+such tables in our application, but if you add one later, long after you've
+forgotten about this tutorial, you won't be left scratching your head when it
+doesn't work.
+
+ .. literalinclude:: src/basiclayout/tutorial/__init__.py
+ :lines: 15
+ :language: py
+
+.. END moved from Application configuration with ``__init__.py``
+
In a SQLAlchemy-based application, a *model* object is an object composed by
querying the SQL database. The ``models`` package is where the ``alchemy``
scaffold put the classes that implement our models.