Django18初体验


1485 浏览 5 years, 11 months

20 django模板过滤器和标签

版权声明: 转载请注明出处 http://www.codingsoho.com/

include

将base.html里面<nav>…</nav>的代码块移到navbar.html里面
In base.html, move the navbar code <nav>…</nav> to navbar.html
在base.html里面添加include
And include it in base.html

{% include 'navbar.html' %}

verbatim可以保持原来的格式

{% include 'navbar.html' %}
{% verbatim %}

同样的方法,可以添加head_css.html和javascript.html,别忘了在文件开始添加 load staticfile

extents

在 home.html中, 添加

{% extends "base.html" %}

block

将div jumbotron移到home.html,用block jumbotron标记
http://getbootstrap.com/examples/jumbotron/

{% block "jumbotron" %}
    <!-- Main component for a primary marketing message or call to action -->
    <div class="jumbotron">
    <h1>Navbar example</h1>
    <p>This example is a quick exercise to illustrate how the default, static and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
    <p>To see the difference between static and fixed top navbars, just scroll.</p>
    <p>
      <a class="btn btn-lg btn-primary" href="../../components/#navbar" role="button">View navbar docs &raquo;</a>
    </p>
    </div>
{% endblock%}

并且在 base.html中添加block jumbotron

{% block "jumbotron" %}
{% endblock%}

{{block.super}} 会显示super内容.

In base.html

<title>{% block head_title %}MVP Landing{% endblock %}</title>

In home.html

{% block head_title %}Welcome | {{ block.super }}{% endblock %}