From b1b92284f496800a4dfd2cea72cb9be07ba8661c Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 16:52:14 -0400 Subject: First cut at import of quick tutorial. --- docs/quick_tutorial/jinja2.rst | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 docs/quick_tutorial/jinja2.rst (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst new file mode 100644 index 000000000..ad5b8a9ca --- /dev/null +++ b/docs/quick_tutorial/jinja2.rst @@ -0,0 +1,96 @@ +============================== +12: Templating With ``jinja2`` +============================== + +We just said Pyramid doesn't prefer one templating language over +another. Time to prove it. Jinja2 is a popular templating system, +used in Flask and modelled after Django's templates. Let's add +``pyramid_jinja2``, a Pyramid :term:`add-on` which enables Jinja2 as a +:term:`renderer` in our Pyramid applications. + +Objectives +========== + +- Show Pyramid's support for different templating systems + +- Learn about installing Pyramid add-ons + +Steps +===== + +#. In this step let's start by installing the ``pyramid_jinja2`` + add-on, the copying the ``view_class`` step's directory: + + .. code-block:: bash + + (env27)$ cd ..; cp -r view_classes jinja2; cd jinja2 + (env27)$ python setup.py develop + (env27)$ easy_install pyramid_jinja2 + +#. We need to add an item to ``pyramid.includes`` in + ``jinja2/development.ini``: + + .. literalinclude:: jinja2/development.ini + :language: ini + :linenos: + +#. Our ``jinja2/tutorial/views.py`` simply changes its ``renderer``: + + .. literalinclude:: jinja2/tutorial/views.py + :linenos: + +#. Add ``jinja2/tutorial/home.jinja2`` as a template: + + .. literalinclude:: jinja2/tutorial/home.jinja2 + :language: html + +#. Get the ``pyramid.includes`` into the functional test setup in + ``jinja2/tutorial/tests.py``: + + .. literalinclude:: jinja2/tutorial/tests.py + :linenos: + +#. Now run the tests: + + .. code-block:: bash + + (env27)$ nosetests tutorial + +#. Run your Pyramid application with: + + .. code-block:: bash + + (env27)$ pserve development.ini --reload + +#. Open ``http://localhost:6543/`` in your browser. + +Analysis +======== + +Getting a Pyramid add-on into Pyramid is simple. First you use normal +Python package installation tools to install the add-on package into +your Python. You then tell Pyramid's configurator to run the setup code +in the add-on. In this case the setup code told Pyramid to make a new +"renderer" available that looked for ``.jinja2`` file extensions. + +Our view code stayed largely the same. We simply changed the file +extension on the renderer. For the template, the syntax for Chameleon +and Jinja2's basic variable insertion is very similar. + +Our functional tests don't have ``development.ini`` so they needed the +``pyramid.includes`` to be setup in the test setup. + +Extra Credit +============ + +#. Our project now depends on ``pyramid_jinja2``. We installed that + dependency manually. What is another way we could have made the + association? + +#. We used ``development.ini`` to get the :term:`configurator` to + load ``pyramid_jinja2``'s configuration. What is another way could + include it into the config? + +.. seealso:: `Jinja2 homepage `_, + and + :ref:`pyramid_jinja2 Overview ` -- cgit v1.2.3 From 0a784868bdbc3a0eb226ed00e8d89cda9d181ec5 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 17:11:42 -0400 Subject: Fix naming of virtualenv prefix. --- docs/quick_tutorial/jinja2.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index ad5b8a9ca..bdca65e68 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -23,9 +23,9 @@ Steps .. code-block:: bash - (env27)$ cd ..; cp -r view_classes jinja2; cd jinja2 - (env27)$ python setup.py develop - (env27)$ easy_install pyramid_jinja2 + (env)$ cd ..; cp -r view_classes jinja2; cd jinja2 + (env)$ python setup.py develop + (env)$ easy_install pyramid_jinja2 #. We need to add an item to ``pyramid.includes`` in ``jinja2/development.ini``: @@ -54,13 +54,13 @@ Steps .. code-block:: bash - (env27)$ nosetests tutorial + (env)$ nosetests tutorial #. Run your Pyramid application with: .. code-block:: bash - (env27)$ pserve development.ini --reload + (env)$ pserve development.ini --reload #. Open ``http://localhost:6543/`` in your browser. -- cgit v1.2.3 From b0b28ede912c817a62a84b97c332e39eda02d166 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 16 Sep 2013 02:14:53 +0200 Subject: s/env/venv just for sake of consistency --- docs/quick_tutorial/jinja2.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index bdca65e68..f31dbf491 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -23,9 +23,9 @@ Steps .. code-block:: bash - (env)$ cd ..; cp -r view_classes jinja2; cd jinja2 - (env)$ python setup.py develop - (env)$ easy_install pyramid_jinja2 + (venv)$ cd ..; cp -r view_classes jinja2; cd jinja2 + (venv)$ python setup.py develop + (venv)$ easy_install pyramid_jinja2 #. We need to add an item to ``pyramid.includes`` in ``jinja2/development.ini``: @@ -54,13 +54,13 @@ Steps .. code-block:: bash - (env)$ nosetests tutorial + (venv)$ nosetests tutorial #. Run your Pyramid application with: .. code-block:: bash - (env)$ pserve development.ini --reload + (venv)$ pserve development.ini --reload #. Open ``http://localhost:6543/`` in your browser. -- cgit v1.2.3 From d749bf4c987c4ab90bd5f89326e7d4059e4f47b3 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 16 Sep 2013 02:18:11 +0200 Subject: make example links clickable, for convenience --- docs/quick_tutorial/jinja2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index f31dbf491..8b5c86a81 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -62,7 +62,7 @@ Steps (venv)$ pserve development.ini --reload -#. Open ``http://localhost:6543/`` in your browser. +#. Open http://localhost:6543/ in your browser. Analysis ======== -- cgit v1.2.3 From 187104fd81418beeb51592913041d9751bafe08d Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Wed, 25 Sep 2013 09:27:43 -0400 Subject: Quick Tutorial: Improve the setup instructions (adapted from Steve Piercy's work), particularly for Windows. Change all the steps to use $VENV/bin prefixes on commands (don't presume that they have done source env/bin/activate). --- docs/quick_tutorial/jinja2.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 8b5c86a81..134ab39ca 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -23,9 +23,9 @@ Steps .. code-block:: bash - (venv)$ cd ..; cp -r view_classes jinja2; cd jinja2 - (venv)$ python setup.py develop - (venv)$ easy_install pyramid_jinja2 + $ cd ..; cp -r view_classes jinja2; cd jinja2 + $ $VENV/bin/python setup.py develop + $ $VENV/bin/easy_install pyramid_jinja2 #. We need to add an item to ``pyramid.includes`` in ``jinja2/development.ini``: @@ -54,13 +54,13 @@ Steps .. code-block:: bash - (venv)$ nosetests tutorial + $ $VENV/bin/nosetests tutorial #. Run your Pyramid application with: .. code-block:: bash - (venv)$ pserve development.ini --reload + $ $VENV/bin/pserve development.ini --reload #. Open http://localhost:6543/ in your browser. -- cgit v1.2.3 From b731b5fca253d9d95b3307490aa585e194676c01 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Thu, 26 Sep 2013 17:41:44 -0400 Subject: Quick Tour: shorten the setup part and point to Quick Tutorial Requirements for more explanation. Cross link each Quick Tour section with its Quick Tutorial match. --- docs/quick_tutorial/jinja2.rst | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 134ab39ca..40d941098 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -1,3 +1,5 @@ +.. _qtut_jinja2: + ============================== 12: Templating With ``jinja2`` ============================== -- cgit v1.2.3 From a2b15855bee4893524609a941954c823bfbcec0d Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Tue, 8 Oct 2013 14:33:16 -0400 Subject: Small quick tutorial fixes post conference. --- docs/quick_tutorial/jinja2.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 40d941098..44d9f635b 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -29,11 +29,10 @@ Steps $ $VENV/bin/python setup.py develop $ $VENV/bin/easy_install pyramid_jinja2 -#. We need to add an item to ``pyramid.includes`` in - ``jinja2/development.ini``: +#. We need to include ``pyramid_jinja2`` in + ``jinja2/tutorial/__init__.py``: - .. literalinclude:: jinja2/development.ini - :language: ini + .. literalinclude:: jinja2/tutorial/__init__.py :linenos: #. Our ``jinja2/tutorial/views.py`` simply changes its ``renderer``: -- cgit v1.2.3 From 872796d2c1743430ab04364d05657b46133fa230 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 20 Apr 2014 06:50:44 -0700 Subject: Merge pull request #1309 from omidraha/patch-1 Correct question to adapt to the the text. --- docs/quick_tutorial/jinja2.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 44d9f635b..2f1e295dd 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -88,9 +88,9 @@ Extra Credit dependency manually. What is another way we could have made the association? -#. We used ``development.ini`` to get the :term:`configurator` to - load ``pyramid_jinja2``'s configuration. What is another way could - include it into the config? +#. We used ``config.include`` which is an imperative configuration to get the + :term:`Configurator` to load ``pyramid_jinja2``'s configuration. + What is another way could include it into the config? .. seealso:: `Jinja2 homepage `_, and -- cgit v1.2.3 From c688c70fb2bf6731bbdbf68682eebb203b540a04 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 2 Jul 2014 14:36:27 -0400 Subject: dont need to use any settings, we include pyramid_jinja2 in main --- docs/quick_tutorial/jinja2.rst | 6 ------ 1 file changed, 6 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 2f1e295dd..ad6da7a9e 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -45,12 +45,6 @@ Steps .. literalinclude:: jinja2/tutorial/home.jinja2 :language: html -#. Get the ``pyramid.includes`` into the functional test setup in - ``jinja2/tutorial/tests.py``: - - .. literalinclude:: jinja2/tutorial/tests.py - :linenos: - #. Now run the tests: .. code-block:: bash -- cgit v1.2.3 From 9095de6ac110a7d31ea76a5dbb5b65408897c75e Mon Sep 17 00:00:00 2001 From: David Eisner Date: Wed, 8 Oct 2014 11:46:21 -0400 Subject: Minor edits to Templating With jinja2 * Fix grammar, order of operations in step 1. * Remove Analysis section reference to pyramid.includes in functional tests, which is no longer accurate. --- docs/quick_tutorial/jinja2.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index ad6da7a9e..613542349 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -20,8 +20,8 @@ Objectives Steps ===== -#. In this step let's start by installing the ``pyramid_jinja2`` - add-on, the copying the ``view_class`` step's directory: +#. In this step let's start by copying the ``view_class`` step's + directory, and then installing the ``pyramid_jinja2`` add-on. .. code-block:: bash @@ -72,9 +72,6 @@ Our view code stayed largely the same. We simply changed the file extension on the renderer. For the template, the syntax for Chameleon and Jinja2's basic variable insertion is very similar. -Our functional tests don't have ``development.ini`` so they needed the -``pyramid.includes`` to be setup in the test setup. - Extra Credit ============ -- cgit v1.2.3 From 5cef2824260103212eb96d7d372c72cdc45c4deb Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Fri, 22 May 2015 02:31:36 -0700 Subject: spelling; correct title tag --- docs/quick_tutorial/jinja2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 613542349..2121803f9 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -6,7 +6,7 @@ We just said Pyramid doesn't prefer one templating language over another. Time to prove it. Jinja2 is a popular templating system, -used in Flask and modelled after Django's templates. Let's add +used in Flask and modeled after Django's templates. Let's add ``pyramid_jinja2``, a Pyramid :term:`add-on` which enables Jinja2 as a :term:`renderer` in our Pyramid applications. -- cgit v1.2.3 From 96ca13ad07593fe15c8981e8a0372d749f6bd411 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 7 Apr 2016 03:19:59 -0700 Subject: - update templating.rst --- docs/quick_tutorial/jinja2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 2121803f9..8622e968a 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -27,7 +27,7 @@ Steps $ cd ..; cp -r view_classes jinja2; cd jinja2 $ $VENV/bin/python setup.py develop - $ $VENV/bin/easy_install pyramid_jinja2 + $ $VENV/bin/pip install pyramid_jinja2 #. We need to include ``pyramid_jinja2`` in ``jinja2/tutorial/__init__.py``: -- cgit v1.2.3 From 45fabb70bf376b4ee1ae6594be71577f4e3ebb08 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 7 Apr 2016 03:24:59 -0700 Subject: - update jinja2.rst --- docs/quick_tutorial/jinja2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 8622e968a..6b9d5feba 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -26,7 +26,7 @@ Steps .. code-block:: bash $ cd ..; cp -r view_classes jinja2; cd jinja2 - $ $VENV/bin/python setup.py develop + $ $VENV/bin/pip install -e . $ $VENV/bin/pip install pyramid_jinja2 #. We need to include ``pyramid_jinja2`` in -- cgit v1.2.3 From d5e6762315458de334896096923abcd3d51a31f5 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 16 Apr 2016 06:43:35 -0700 Subject: quick_tutorial cleanup - replace nose with pytest - cleanup jinja2.rst - add pyramid_jinja2 to requirements.rst --- docs/quick_tutorial/jinja2.rst | 55 ++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'docs/quick_tutorial/jinja2.rst') diff --git a/docs/quick_tutorial/jinja2.rst b/docs/quick_tutorial/jinja2.rst index 6b9d5feba..2fc68827b 100644 --- a/docs/quick_tutorial/jinja2.rst +++ b/docs/quick_tutorial/jinja2.rst @@ -4,24 +4,26 @@ 12: Templating With ``jinja2`` ============================== -We just said Pyramid doesn't prefer one templating language over -another. Time to prove it. Jinja2 is a popular templating system, -used in Flask and modeled after Django's templates. Let's add -``pyramid_jinja2``, a Pyramid :term:`add-on` which enables Jinja2 as a -:term:`renderer` in our Pyramid applications. +We just said Pyramid doesn't prefer one templating language over another. Time +to prove it. Jinja2 is a popular templating system, used in Flask and modeled +after Django's templates. Let's add ``pyramid_jinja2``, a Pyramid +:term:`add-on` which enables Jinja2 as a :term:`renderer` in our Pyramid +applications. + Objectives ========== -- Show Pyramid's support for different templating systems +- Show Pyramid's support for different templating systems. + +- Learn about installing Pyramid add-ons. -- Learn about installing Pyramid add-ons Steps ===== -#. In this step let's start by copying the ``view_class`` step's - directory, and then installing the ``pyramid_jinja2`` add-on. +#. In this step let's start by copying the ``view_class`` step's directory, + and then installing the ``pyramid_jinja2`` add-on. .. code-block:: bash @@ -29,8 +31,7 @@ Steps $ $VENV/bin/pip install -e . $ $VENV/bin/pip install pyramid_jinja2 -#. We need to include ``pyramid_jinja2`` in - ``jinja2/tutorial/__init__.py``: +#. We need to include ``pyramid_jinja2`` in ``jinja2/tutorial/__init__.py``: .. literalinclude:: jinja2/tutorial/__init__.py :linenos: @@ -49,7 +50,9 @@ Steps .. code-block:: bash - $ $VENV/bin/nosetests tutorial + $ $VENV/bin/py.test tutorial/tests.py -q + .... + 4 passed in 0.40 seconds #. Run your Pyramid application with: @@ -59,30 +62,30 @@ Steps #. Open http://localhost:6543/ in your browser. + Analysis ======== -Getting a Pyramid add-on into Pyramid is simple. First you use normal -Python package installation tools to install the add-on package into -your Python. You then tell Pyramid's configurator to run the setup code +Getting a Pyramid add-on into Pyramid is simple. First you use normal Python +package installation tools to install the add-on package into your Python +virtual environment. You then tell Pyramid's configurator to run the setup code in the add-on. In this case the setup code told Pyramid to make a new "renderer" available that looked for ``.jinja2`` file extensions. -Our view code stayed largely the same. We simply changed the file -extension on the renderer. For the template, the syntax for Chameleon -and Jinja2's basic variable insertion is very similar. +Our view code stayed largely the same. We simply changed the file extension on +the renderer. For the template, the syntax for Chameleon and Jinja2's basic +variable insertion is very similar. + -Extra Credit +Extra credit ============ -#. Our project now depends on ``pyramid_jinja2``. We installed that - dependency manually. What is another way we could have made the - association? +#. Our project now depends on ``pyramid_jinja2``. We installed that dependency + manually. What is another way we could have made the association? #. We used ``config.include`` which is an imperative configuration to get the - :term:`Configurator` to load ``pyramid_jinja2``'s configuration. - What is another way could include it into the config? + :term:`Configurator` to load ``pyramid_jinja2``'s configuration. What is + another way could include it into the config? -.. seealso:: `Jinja2 homepage `_, - and +.. seealso:: `Jinja2 homepage `_, and :ref:`pyramid_jinja2 Overview ` -- cgit v1.2.3