简体   繁体   English

金字塔变色龙基础模板方向

[英]Pyramid Chameleon base template orientation

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. 我是Pyramid的新手,过去曾使用Django,但找不到关于如何在Pyramid Chameleon模板中使用基本模板的清晰说明。

I have a very simple .pt file which I want to be my base.pt template it's something like this: 我有一个非常简单的.pt文件,我想成为我的base.pt模板,它是这样的:

<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 ? 如您所见,我尝试在项目的以下所有模板中都包含bootstrap标头,那么我需要具备什么条件才能使所有模板继承或将base.pt作为基本模板? In Django I will just use {% include base.html %} 在Django中,我将只使用{% include base.html %}

Chameleon and Mako are the two templating languages with support currently bundled within Pyramid. Chameleon和Mako是目前在Pyramid中捆绑在一起的两种模板语言。 However, Jinja2 is officially supported by the pyramid_jinja2 addon and is easily activated. 但是, jinja2pyramid_jinja2插件正式支持,并且很容易激活。 Jinja2 provides a syntax very similar to Django's if you do not wish to learn Chameleon. 如果您不想学习Chameleon,Jinja2提供的语法与Django非常相似。

config.include('pyramid_jinja2')

@view_config(..., renderer='myapp:templates/home.jinja2')
def view(request):
    return {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM