summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSteve Piercy <web@stevepiercy.com>2016-04-16 05:02:30 -0700
committerSteve Piercy <web@stevepiercy.com>2016-04-16 05:02:30 -0700
commit3dece91a06679f1af98c864160fcd06ec3f15b8c (patch)
treeb6a49930087950cb566eb29c30c8cfa3742de2f9 /docs
parent8083654303f0f0b3ce5e78979f6b51f7afd6980c (diff)
downloadpyramid-3dece91a06679f1af98c864160fcd06ec3f15b8c.tar.gz
pyramid-3dece91a06679f1af98c864160fcd06ec3f15b8c.tar.bz2
pyramid-3dece91a06679f1af98c864160fcd06ec3f15b8c.zip
quick_tutorial cleanup
- replace nose with pytest - cleanup templating.rst
Diffstat (limited to 'docs')
-rw-r--r--docs/quick_tutorial/templating.rst84
1 files changed, 40 insertions, 44 deletions
diff --git a/docs/quick_tutorial/templating.rst b/docs/quick_tutorial/templating.rst
index a975d9ec2..dbcf76a0a 100644
--- a/docs/quick_tutorial/templating.rst
+++ b/docs/quick_tutorial/templating.rst
@@ -4,50 +4,52 @@
08: HTML Generation With Templating
===================================
-Most web frameworks don't embed HTML in programming code. Instead,
-they pass data into a templating system. In this step we look at the
-basics of using HTML templates in Pyramid.
+Most web frameworks don't embed HTML in programming code. Instead, they pass
+data into a templating system. In this step we look at the basics of using HTML
+templates in Pyramid.
+
Background
==========
-Ouch. We have been making our own ``Response`` and filling the response
-body with HTML. You usually won't embed an HTML string directly in
-Python, but instead, will use a templating language.
+Ouch. We have been making our own ``Response`` and filling the response body
+with HTML. You usually won't embed an HTML string directly in Python, but
+instead will use a templating language.
+
+Pyramid doesn't mandate a particular database system, form library, and so on.
+It encourages replaceability. This applies equally to templating, which is
+fortunate: developers have strong views about template languages. As of
+Pyramid 1.5a2, Pyramid doesn't even bundle a template language!
-Pyramid doesn't mandate a particular database system, form library,
-etc. It encourages replaceability. This applies equally to templating,
-which is fortunate: developers have strong views about template
-languages. As of Pyramid 1.5a2, Pyramid doesn't even bundle a template
-language!
+It does, however, have strong ties to Jinja2, Mako, and Chameleon. In this step
+we see how to add ``pyramid_chameleon`` to your project, then change your views
+to use templating.
-It does, however, have strong ties to Jinja2, Mako, and Chameleon. In
-this step we see how to add ``pyramid_chameleon`` to your project,
-then change your views to use templating.
Objectives
==========
-- Enable the ``pyramid_chameleon`` Pyramid add-on
+- Enable the ``pyramid_chameleon`` Pyramid add-on.
+
+- Generate HTML from template files.
-- Generate HTML from template files
+- Connect the templates as "renderers" for view code.
-- Connect the templates as "renderers" for view code
+- Change the view code to simply return data.
-- Change the view code to simply return data
Steps
=====
-#. Let's begin by using the previous package as a starting point for a
- new project:
+#. Let's begin by using the previous package as a starting point for a new
+ project:
.. code-block:: bash
$ cd ..; cp -r views templating; cd templating
-#. This step depends on ``pyramid_chameleon``, so add it as a dependency
- in ``templating/setup.py``:
+#. This step depends on ``pyramid_chameleon``, so add it as a dependency in
+ ``templating/setup.py``:
.. literalinclude:: templating/setup.py
:linenos:
@@ -58,8 +60,8 @@ Steps
$ $VENV/bin/pip install -e .
-#. We need to connect ``pyramid_chameleon`` as a renderer by making a
- call in the setup of ``templating/tutorial/__init__.py``:
+#. We need to connect ``pyramid_chameleon`` as a renderer by making a call in
+ the setup of ``templating/tutorial/__init__.py``:
.. literalinclude:: templating/tutorial/__init__.py
:linenos:
@@ -74,14 +76,13 @@ Steps
.. literalinclude:: templating/tutorial/home.pt
:language: html
-#. For convenience, change ``templating/development.ini`` to reload
- templates automatically with ``pyramid.reload_templates``:
+#. For convenience, change ``templating/development.ini`` to reload templates
+ automatically with ``pyramid.reload_templates``:
.. literalinclude:: templating/development.ini
:language: ini
-#. Our unit tests in ``templating/tutorial/tests.py`` can focus on
- data:
+#. Our unit tests in ``templating/tutorial/tests.py`` can focus on data:
.. literalinclude:: templating/tutorial/tests.py
:linenos:
@@ -90,13 +91,9 @@ Steps
.. code-block:: bash
-
- $ $VENV/bin/nosetests tutorial
- .
- ----------------------------------------------------------------------
- Ran 4 tests in 0.141s
-
- OK
+ $ $VENV/bin/py.test tutorial/tests.py -q
+ ....
+ 4 passed in 0.46 seconds
#. Run your Pyramid application with:
@@ -104,20 +101,19 @@ Steps
$ $VENV/bin/pserve development.ini --reload
-#. Open http://localhost:6543/ and http://localhost:6543/howdy
- in your browser.
+#. Open http://localhost:6543/ and http://localhost:6543/howdy in your browser.
+
Analysis
========
-Ahh, that looks better. We have a view that is focused on Python code.
-Our ``@view_config`` decorator specifies a :term:`renderer` that points
-to our template file. Our view then simply returns data which is then
-supplied to our template. Note that we used the same template for both
-views.
+Ahh, that looks better. We have a view that is focused on Python code. Our
+``@view_config`` decorator specifies a :term:`renderer` that points to our
+template file. Our view then simply returns data which is then supplied to our
+template. Note that we used the same template for both views.
-Note the effect on testing. We can focus on having a data-oriented
-contract with our view code.
+Note the effect on testing. We can focus on having a data-oriented contract
+with our view code.
.. seealso:: :ref:`templates_chapter`, :ref:`debugging_templates`, and
:ref:`available_template_system_bindings`.