summaryrefslogtreecommitdiff
path: root/docs/tutorials/wiki
diff options
context:
space:
mode:
authorSteve Piercy <web@stevepiercy.com>2019-12-27 22:12:44 -0800
committerSteve Piercy <web@stevepiercy.com>2020-01-02 23:30:59 -0800
commit2e73919835c6480b6c5eb57dfb368812d6df9d43 (patch)
tree601487d9e666f626c04eed84122f7087f63e86a3 /docs/tutorials/wiki
parent5157b14655d7ff2b3780715ea38217125dd93003 (diff)
downloadpyramid-2e73919835c6480b6c5eb57dfb368812d6df9d43.tar.gz
pyramid-2e73919835c6480b6c5eb57dfb368812d6df9d43.tar.bz2
pyramid-2e73919835c6480b6c5eb57dfb368812d6df9d43.zip
Update docs/tutorials/wiki/basiclayout.rst and related files
Diffstat (limited to 'docs/tutorials/wiki')
-rw-r--r--docs/tutorials/wiki/basiclayout.rst18
-rw-r--r--docs/tutorials/wiki/src/basiclayout/tutorial/templates/layout.pt2
-rw-r--r--docs/tutorials/wiki/src/basiclayout/tutorial/tests.py6
-rw-r--r--docs/tutorials/wiki/src/basiclayout/tutorial/views/default.py2
-rw-r--r--docs/tutorials/wiki/src/basiclayout/tutorial/views/notfound.py2
5 files changed, 21 insertions, 9 deletions
diff --git a/docs/tutorials/wiki/basiclayout.rst b/docs/tutorials/wiki/basiclayout.rst
index 52d3f4670..4eb5c4283 100644
--- a/docs/tutorials/wiki/basiclayout.rst
+++ b/docs/tutorials/wiki/basiclayout.rst
@@ -107,6 +107,12 @@ Next include routes from the ``.routes`` module.
:lineno-match:
:language: py
+The included module contains the following function.
+
+.. literalinclude:: src/basiclayout/tutorial/routes.py
+ :linenos:
+ :language: py
+
This registers a "static view" using the :meth:`pyramid.config.Configurator.add_static_view` method.
This view answers requests whose URL path starts with ``/static``.
This statement registers a view that will serve up static assets, such as CSS and image files.
@@ -121,7 +127,7 @@ Alternatively the cookiecutter could have used an *absolute* asset specification
The third argument is an optional ``cache_max_age`` which specifies the number of seconds the static asset will be HTTP-cached.
-Next perform a :term:`scan`.
+Back into our ``__init__.py``, next perform a :term:`scan`.
.. literalinclude:: src/basiclayout/tutorial/__init__.py
:lines: 21
@@ -208,12 +214,12 @@ Let's try to understand the components in this module:
The ``context`` argument signifies that the decorated view callable ``my_view`` should only be run when :term:`traversal` finds the ``tutorial.models.MyModel`` :term:`resource` as the :term:`context` of a request.
In English this means that when the URL ``/`` is visited, and because ``MyModel`` is the root model, this view callable will be invoked.
- The ``renderer`` argument names an :term:`asset specification` of ``templates/mytemplate.pt``.
+ The ``renderer`` argument names an :term:`asset specification` of ``tutorial:templates/mytemplate.pt``.
This asset specification points at a :term:`Chameleon` template which lives in the ``mytemplate.pt`` file within the ``templates`` directory of the ``tutorial`` package.
And indeed if you look in the ``templates`` directory of this package, you will see a ``mytemplate.pt`` template file
This template renders the default home page of the generated project.
- This asset specification is *relative* to the ``views`` package.
- Alternatively we could have used the absolute asset specification ``tutorial:templates/mytemplate.pt``.
+ This asset specification is *absolute* to the ``views`` package.
+ Alternatively we could have used the relative asset specification ``../templates/mytemplate.pt``.
Since this call to ``@view_config`` doesn't pass a ``name`` argument, the ``my_view`` function which it decorates represents the "default" view callable used when the context is of the type ``MyModel``.
@@ -225,7 +231,7 @@ Let's try to understand the components in this module:
The function returns the dictionary ``{'project': 'myproj'}``.
This dictionary is used by the template named by the ``mytemplate.pt`` asset specification to fill in certain values on the page.
-Let us open ``tutorial/views/default.py`` in the ``views`` package to look at the second view.
+Let us open ``tutorial/views/notfound.py`` in the ``views`` package to look at the second view.
.. literalinclude:: src/basiclayout/tutorial/views/notfound.py
:linenos:
@@ -237,7 +243,7 @@ Without repeating ourselves, we will point out the differences between this view
The ``notfound_view`` function is decorated with ``@notfound_view_config``.
This decorator registers a :term:`Not Found View` using :meth:`pyramid.config.Configurator.add_notfound_view`.
- The ``renderer`` argument names an :term:`asset specification` of ``templates/404.pt``.
+ The ``renderer`` argument names an :term:`asset specification` of ``tutorial:templates/404.pt``.
#. *Lines 5-7*.
A :term:`view callable` named ``notfound_view`` is defined, which is decorated in the step above.
diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/templates/layout.pt b/docs/tutorials/wiki/src/basiclayout/tutorial/templates/layout.pt
index 9fdaef00f..9ca01382b 100644
--- a/docs/tutorials/wiki/src/basiclayout/tutorial/templates/layout.pt
+++ b/docs/tutorials/wiki/src/basiclayout/tutorial/templates/layout.pt
@@ -1,5 +1,5 @@
<!DOCTYPE html metal:define-macro="layout">
-<html lang="{{request.locale_name}}">
+<html lang="${request.locale_name}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py b/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py
index 6279d9f66..aa5641cdd 100644
--- a/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py
+++ b/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py
@@ -16,3 +16,9 @@ class ViewTests(unittest.TestCase):
info = my_view(request)
self.assertEqual(info['project'], 'myproj')
+ def test_notfound_view(self):
+ from .views.notfound import notfound_view
+ request = testing.DummyRequest()
+ info = notfound_view(request)
+ self.assertEqual(info, {})
+
diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/views/default.py b/docs/tutorials/wiki/src/basiclayout/tutorial/views/default.py
index 5d708d15c..51ec5ed98 100644
--- a/docs/tutorials/wiki/src/basiclayout/tutorial/views/default.py
+++ b/docs/tutorials/wiki/src/basiclayout/tutorial/views/default.py
@@ -3,6 +3,6 @@ from pyramid.view import view_config
from ..models import MyModel
-@view_config(context=MyModel, renderer='../templates/mytemplate.pt')
+@view_config(context=MyModel, renderer='tutorial:templates/mytemplate.pt')
def my_view(request):
return {'project': 'myproj'}
diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/views/notfound.py b/docs/tutorials/wiki/src/basiclayout/tutorial/views/notfound.py
index 728791d0a..59a37280e 100644
--- a/docs/tutorials/wiki/src/basiclayout/tutorial/views/notfound.py
+++ b/docs/tutorials/wiki/src/basiclayout/tutorial/views/notfound.py
@@ -1,7 +1,7 @@
from pyramid.view import notfound_view_config
-@notfound_view_config(renderer='../templates/404.pt')
+@notfound_view_config(renderer='tutorial:templates/404.pt')
def notfound_view(request):
request.response.status = 404
return {}