summaryrefslogtreecommitdiff
path: root/docs/quick_tutorial/static_assets.rst
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2016-04-17 15:11:14 -0400
committerChris McDonough <chrism@plope.com>2016-04-17 15:11:14 -0400
commit97ab509ae27ce08992ccfbad8eba91613779dee3 (patch)
treeaf4cad2d4d8c3e065ff390d1b9874c8038a623a4 /docs/quick_tutorial/static_assets.rst
parentdf7a123a847e2243f38688c033f06200382ba139 (diff)
parent61663444a805f432638e6edf7cca76213f0d6029 (diff)
downloadpyramid-97ab509ae27ce08992ccfbad8eba91613779dee3.tar.gz
pyramid-97ab509ae27ce08992ccfbad8eba91613779dee3.tar.bz2
pyramid-97ab509ae27ce08992ccfbad8eba91613779dee3.zip
Merge branch 'master' of github.com:Pylons/pyramid
Diffstat (limited to 'docs/quick_tutorial/static_assets.rst')
-rw-r--r--docs/quick_tutorial/static_assets.rst47
1 files changed, 25 insertions, 22 deletions
diff --git a/docs/quick_tutorial/static_assets.rst b/docs/quick_tutorial/static_assets.rst
index 3a7496ec7..65b34f8f9 100644
--- a/docs/quick_tutorial/static_assets.rst
+++ b/docs/quick_tutorial/static_assets.rst
@@ -4,16 +4,17 @@
13: CSS/JS/Images Files With 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 where
-Pyramid will serve some 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 where Pyramid will serve
+some static assets.
Objectives
==========
-- Publish a directory of static assets at a URL
+- Publish a directory of static assets at a URL.
+
+- Use Pyramid to help generate URLs to files in that directory.
-- Use Pyramid to help generate URLs to files in that directory
Steps
=====
@@ -23,7 +24,7 @@ Steps
.. code-block:: bash
$ cd ..; cp -r view_classes static_assets; cd static_assets
- $ $VENV/bin/python setup.py develop
+ $ $VENV/bin/pip install -e .
#. We add a call ``config.add_static_view`` in
``static_assets/tutorial/__init__.py``:
@@ -37,8 +38,7 @@ Steps
.. literalinclude:: static_assets/tutorial/home.pt
:language: html
-#. Add a CSS file at
- ``static_assets/tutorial/static/app.css``:
+#. Add a CSS file at ``static_assets/tutorial/static/app.css``:
.. literalinclude:: static_assets/tutorial/static/app.css
:language: css
@@ -47,7 +47,9 @@ Steps
.. code-block:: bash
- $ $VENV/bin/nosetests tutorial
+ $ $VENV/bin/$VENV/bin/py.test tutorial/tests.py -q
+ ....
+ 4 passed in 0.50 seconds
#. Run your Pyramid application with:
@@ -57,30 +59,31 @@ Steps
#. Open http://localhost:6543/ in your browser and note the new font.
+
Analysis
========
We changed our WSGI application to map requests under
-http://localhost:6543/static/ to files and directories inside a
-``static`` directory inside our ``tutorial`` package. This directory
-contained ``app.css``.
+http://localhost:6543/static/ to files and directories inside a ``static``
+directory inside our ``tutorial`` package. This directory contained
+``app.css``.
-We linked to the CSS in our template. We could have hard-coded this
-link to ``/static/app.css``. But what if the site is later moved under
-``/somesite/static/``? Or perhaps the web developer changes the
-arrangement on disk? Pyramid gives a helper that provides flexibility
-on URL generation:
+We linked to the CSS in our template. We could have hard-coded this link to
+``/static/app.css``. But what if the site is later moved under
+``/somesite/static/``? Or perhaps the web developer changes the arrangement on
+disk? Pyramid gives a helper that provides flexibility on URL generation:
.. code-block:: html
${request.static_url('tutorial:static/app.css')}
-This matches the ``path='tutorial:static'`` in our
-``config.add_static_view`` registration. 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.
+This matches the ``path='tutorial:static'`` in our ``config.add_static_view``
+registration. 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.
+
-Extra Credit
+Extra credit
============
#. There is also a ``request.static_path`` API. How does this differ from