Steve Piercy
2016-06-16 8bce7fb5d33c1fc55242073acceed85baec6da29
Quick Tour - static_assets - closes #2648
- swap contents of jinja2 templates
- use __main__ to specify package
- carry forward template to json step
- use :language: python directive for correct syntax highlighting
(cherry picked from commit 715ec5e)
4 files modified
19 ■■■■ changed files
docs/quick_tour.rst 13 ●●●● patch | view | raw | blame | history
docs/quick_tour/json/hello_world.jinja2 2 ●●● patch | view | raw | blame | history
docs/quick_tour/static_assets/hello_world.jinja2 2 ●●● patch | view | raw | blame | history
docs/quick_tour/static_assets/hello_world_static.jinja2 2 ●●● patch | view | raw | blame | history
docs/quick_tour.rst
@@ -334,9 +334,10 @@
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
@@ -354,7 +355,7 @@
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
@@ -366,16 +367,16 @@
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>`,
docs/quick_tour/json/hello_world.jinja2
@@ -2,7 +2,7 @@
<html lang="en">
<head>
    <title>Hello World</title>
    <link rel="stylesheet" href="{{ request.static_url('static/app.css') }}"/>
    <link rel="stylesheet" href="{{ request.static_url('__main__:static/app.css') }}"/>
</head>
<body>
<h1>Hello {{ name }}!</h1>
docs/quick_tour/static_assets/hello_world.jinja2
@@ -2,7 +2,7 @@
<html lang="en">
<head>
    <title>Hello World</title>
    <link rel="stylesheet" href="/static/app.css"/>
    <link rel="stylesheet" href="{{ request.static_url('__main__:static/app.css') }}"/>
</head>
<body>
<h1>Hello {{ name }}!</h1>
docs/quick_tour/static_assets/hello_world_static.jinja2
@@ -2,7 +2,7 @@
<html lang="en">
<head>
    <title>Hello World</title>
    <link rel="stylesheet" href="{{ request.static_url('static/app.css') }}"/>
    <link rel="stylesheet" href="/static/app.css"/>
</head>
<body>
<h1>Hello {{ name }}!</h1>