Question

I'm very new at Pyramid, I have used Django in the past, but I can't find a clean explanation of how to use base templating in Pyramid Chameleon templates.

I have a very simple .pt file which I want to be my base.pt template it's something like this:

<link href="static/bootstrap/css/bootstrap.css" rel="stylesheet">
<head>
</head>
<body>

<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
  <div class="container">
    <div class="navbar-header">
      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
      </button>
      <a href="#" class="navbar-brand">My project</a>
    </div>
  </div>
</header>

</body>
</html>

As you can see I try to have bootstrap header in all the following templates of my project, so what do I need to have so that all templates inherit or have base.pt as base template ? In Django I will just use {% include base.html %}

Was it helpful?

Solution

Chameleon and Mako are the two templating languages with support currently bundled within Pyramid. However, Jinja2 is officially supported by the pyramid_jinja2 addon and is easily activated. Jinja2 provides a syntax very similar to Django's if you do not wish to learn Chameleon.

config.include('pyramid_jinja2')

@view_config(..., renderer='myapp:templates/home.jinja2')
def view(request):
    return {}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top