Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
126 lines (83 sloc) 3.09 KB

1: Template Layout Preparation

Get a Bootstrap-themed set of Jinja2 templates in place.


In this traversal tutorial we'll have a number of views and templates, each with some styling and layout. Let's work efficiently and produce decent visual appeal by getting some views and Jinja2 templates with our basic layout.


  • Get a basic Pyramid project in place with views and templates based on pyramid_jinja2
  • Have a "layout" master template and some included subtemplates


  1. Let's start with an empty hierarchy of directories. Starting in a tutorial workspace (e.g. traversal):

    $ mkdir -p layout/tutorial/templates
    $ cd layout
  2. Make a layout/

  3. You can now install the project in development mode:

    $ $VENV/bin/python develop
  4. We need a configuration file at layout/development.ini:

  5. In layout/tutorial/ wire up pyramid_jinja2 and scan for views:

  6. Our views in layout/tutorial/ just has a single view that will answer an incoming request for /hello:

  7. The view's renderer points to a template at layout/tutorial/templates/site.jinja2:

  8. That template asks to use a master "layout" template at layout/tutorial/templates/layout.jinja2:

  9. The layout includes a header at layout/tutorial/templates/header.jinja2:

  10. The layout also includes a subtemplate for breadcrumbs at layout/tutorial/templates/breadcrumbs.jinja2:

  11. Simplified tests in layout/tutorial/

  12. Now run the tests:

    $ $VENV/bin/nosetests tutorial
    Ran 2 tests in 0.141s
  13. Run your Pyramid application with:

    $ $VENV/bin/pserve development.ini --reload
  14. Open http://localhost:6543/hello in your browser.


The @view_config uses a new attribute: name="hello". This, as we'll see in this traversal tutorial, makes a hello hop available in URLs.

The view's renderer uses Jinja2's mechanism for pointing at a master layout and filling certain areas from the view templates. The layout points at Twitter Bootstrap CSS on the network provides a basic HTML layout.

Jump to Line
Something went wrong with that request. Please try again.