summaryrefslogtreecommitdiff
path: root/docs/quick_tour.rst
diff options
context:
space:
mode:
authorcewing <cris@crisewing.com>2016-10-22 12:35:21 -0400
committercewing <cris@crisewing.com>2016-10-22 12:35:21 -0400
commit03f6d630364a9adf438e0bd7d7b9f3bc3175f093 (patch)
treede2aed9476c9d569375287a4ea89e9faf0f7b73a /docs/quick_tour.rst
parent1610c8fd3605f2ed481c37da27a1ce059419888a (diff)
parente73ae375581539ed42aa97d7cd6e96e6fbd64c79 (diff)
downloadpyramid-03f6d630364a9adf438e0bd7d7b9f3bc3175f093.tar.gz
pyramid-03f6d630364a9adf438e0bd7d7b9f3bc3175f093.tar.bz2
pyramid-03f6d630364a9adf438e0bd7d7b9f3bc3175f093.zip
Merge branch 'master' into issue.2614
Diffstat (limited to 'docs/quick_tour.rst')
-rw-r--r--docs/quick_tour.rst46
1 files changed, 33 insertions, 13 deletions
diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst
index b170e5d98..39b4cafb3 100644
--- a/docs/quick_tour.rst
+++ b/docs/quick_tour.rst
@@ -1,3 +1,4 @@
+
.. _quick_tour:
=====================
@@ -43,22 +44,24 @@ For Windows:
.. parsed-literal::
# set an environment variable to where you want your virtual environment
- c:\> set VENV=c:\env
+ c:\\> set VENV=c:\\env
# create the virtual environment
- c:\\> c:\\Python35\\python3 -m venv %VENV%
+ c:\\> %VENV%\\Scripts\\python -m venv %VENV%
# install pyramid
c:\\> %VENV%\\Scripts\\pip install pyramid
# or for a specific released version
c:\\> %VENV%\\Scripts\\pip install "pyramid==\ |release|\ "
-Of course Pyramid runs fine on Python 2.6+, as do the examples in this *Quick
+Of course Pyramid runs fine on Python 2.7+, as do the examples in this *Quick
Tour*. We're showing Python 3 for simplicity. (Pyramid had production support
for Python 3 in October 2011.) Also for simplicity, the remaining examples will
show only UNIX commands.
.. seealso:: See also:
:ref:`Quick Tutorial section on Requirements <qtut_requirements>`,
- :ref:`installing_unix`, :ref:`Before You Install <installing_chapter>`, and
+ :ref:`installing_unix`, :ref:`Before You Install <installing_chapter>`,
+ :ref:`Why use $VENV/bin/pip instead of source bin/activate, then pip
+ <venv-bin-pip-vs-source-bin-activate>`, and
:ref:`Installing Pyramid on a Windows System <installing_windows>`.
@@ -70,6 +73,7 @@ step. Here's a tiny application in Pyramid:
.. literalinclude:: quick_tour/hello_world/app.py
:linenos:
+ :language: python
This simple example is easy to run. Save this as ``app.py`` and run it:
@@ -120,6 +124,7 @@ library for request and response handling. In our example above, Pyramid hands
Let's see some features of requests and responses in action:
.. literalinclude:: quick_tour/requests/app.py
+ :language: python
:pyobject: hello_world
In this Pyramid view, we get the URL being visited from ``request.url``. Also
@@ -159,6 +164,7 @@ Let's move the views out to their own ``views.py`` module and change the
First our revised ``app.py``:
.. literalinclude:: quick_tour/views/app.py
+ :language: python
:linenos:
We added some more routes, but we also removed the view code. Our views and
@@ -169,6 +175,7 @@ We now have a ``views.py`` module that is focused on handling requests and
responses:
.. literalinclude:: quick_tour/views/views.py
+ :language: python
:linenos:
We have four views, each leading to the other. If you start at
@@ -214,6 +221,7 @@ What if we want part of the URL to be available as data in my view? We can use
this route declaration, for example:
.. literalinclude:: quick_tour/routing/app.py
+ :language: python
:linenos:
:lines: 6
:lineno-start: 6
@@ -222,6 +230,7 @@ With this, URLs such as ``/howdy/amy/smith`` will assign ``amy`` to ``first``
and ``smith`` to ``last``. We can then use this data in our view:
.. literalinclude:: quick_tour/routing/views.py
+ :language: python
:linenos:
:lines: 5-8
:lineno-start: 5
@@ -260,6 +269,7 @@ With the package installed, we can include the template bindings into our
configuration in ``app.py``:
.. literalinclude:: quick_tour/templating/app.py
+ :language: python
:linenos:
:lines: 6-8
:lineno-start: 6
@@ -268,6 +278,7 @@ configuration in ``app.py``:
Now lets change our ``views.py`` file:
.. literalinclude:: quick_tour/templating/views.py
+ :language: python
:linenos:
:emphasize-lines: 4,6
@@ -304,6 +315,7 @@ With the package installed, we can include the template bindings into our
configuration:
.. literalinclude:: quick_tour/jinja2/app.py
+ :language: python
:linenos:
:lines: 6-8
:lineno-start: 6
@@ -312,6 +324,7 @@ configuration:
The only change in our view is to point the renderer at the ``.jinja2`` file:
.. literalinclude:: quick_tour/jinja2/views.py
+ :language: python
:linenos:
:lines: 4-6
:lineno-start: 4
@@ -339,9 +352,10 @@ Static assets
Of course the Web is more than just markup. You need static assets: CSS, JS,
and images. Let's point our web app at a directory from which Pyramid will
serve some static assets. First let's make another call to the
-:term:`configurator`:
+:term:`configurator` in ``app.py``:
.. literalinclude:: quick_tour/static_assets/app.py
+ :language: python
:linenos:
:lines: 6-8
:lineno-start: 6
@@ -359,7 +373,7 @@ Next make a directory named ``static``, and place ``app.css`` inside:
All we need to do now is point to it in the ``<head>`` of our Jinja2 template,
``hello_world.jinja2``:
-.. literalinclude:: quick_tour/static_assets/hello_world.jinja2
+.. literalinclude:: quick_tour/static_assets/hello_world_static.jinja2
:language: jinja
:linenos:
:lines: 4-6
@@ -371,16 +385,16 @@ the site is later moved under ``/somesite/static/``? Or perhaps a web developer
changes the arrangement on disk? Pyramid provides a helper to allow flexibility
on URL generation:
-.. literalinclude:: quick_tour/static_assets/hello_world_static.jinja2
+.. literalinclude:: quick_tour/static_assets/hello_world.jinja2
:language: jinja
:linenos:
:lines: 4-6
:lineno-start: 4
:emphasize-lines: 2
-By using ``request.static_url`` to generate the full URL to the static
-assets, you both ensure you stay in sync with the configuration and
-gain refactoring flexibility later.
+By using ``request.static_url`` to generate the full URL to the static assets,
+you ensure that you stay in sync with the configuration and gain refactoring
+flexibility later.
.. seealso:: See also:
:ref:`Quick Tutorial Static Assets <qtut_static_assets>`,
@@ -396,6 +410,7 @@ to update the UI in the browser by requesting server data as JSON. Pyramid
supports this with a JSON renderer:
.. literalinclude:: quick_tour/json/views.py
+ :language: python
:linenos:
:lines: 9-
:lineno-start: 9
@@ -408,6 +423,7 @@ We also need to add a route to ``app.py`` so that our app will know how to
respond to a request for ``hello.json``.
.. literalinclude:: quick_tour/json/app.py
+ :language: python
:linenos:
:lines: 6-8
:lineno-start: 6
@@ -437,6 +453,7 @@ The following shows a "Hello World" example with three operations: view a form,
save a change, or press the delete button in our ``views.py``:
.. literalinclude:: quick_tour/view_classes/views.py
+ :language: python
:linenos:
:lines: 7-
:lineno-start: 7
@@ -489,10 +506,10 @@ Pyramid's ``pcreate`` command can list the available scaffolds:
$ pcreate --list
Available scaffolds:
- alchemy: Pyramid SQLAlchemy project using url dispatch
+ alchemy: Pyramid project using SQLAlchemy, SQLite, URL dispatch, and Jinja2
pyramid_jinja2_starter: Pyramid Jinja2 starter project
- starter: Pyramid starter project
- zodb: Pyramid ZODB project using traversal
+ starter: Pyramid starter project using URL dispatch and Chameleon
+ zodb: Pyramid project using ZODB, traversal, and Chameleon
The ``pyramid_jinja2`` add-on gave us a scaffold that we can use. From the
parent directory of where we want our Python package to be generated, let's use
@@ -728,6 +745,7 @@ Our unit test passed, although its coverage is incomplete. What did our test
look like?
.. literalinclude:: quick_tour/package/hello_world/tests.py
+ :language: python
:linenos:
Pyramid supplies helpers for test writing, which we use in the test setup and
@@ -881,6 +899,7 @@ SQLAlchemy uses "models" for this mapping. The scaffold generated a sample
model:
.. literalinclude:: quick_tour/sqla_demo/sqla_demo/models/mymodel.py
+ :language: python
:start-after: Start Sphinx Include
:end-before: End Sphinx Include
@@ -888,6 +907,7 @@ View code, which mediates the logic between web requests and the rest of the
system, can then easily get at the data thanks to SQLAlchemy:
.. literalinclude:: quick_tour/sqla_demo/sqla_demo/views/default.py
+ :language: python
:start-after: Start Sphinx Include
:end-before: End Sphinx Include