当前位置: 动力学知识库 > 问答 > 编程问答 >

python - include common headers and footers

问题描述:

instead of writing a common header and footer like CSS, scripts etc in every template, how can I attach templates with common header and footer files.

网友答案:

In order to extend both a header and a footer from a html template, you should have both header/footer in the same file, and add a jinja block for each place where you would like to add content. (You should really read some documentation first though)

Then, in the specific page, you start with {% extends "base.html" %} where base is your template, and you write each of your block specific to this page.

Here is an example of this :

{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
    <style type="text/css">
        .important { color: #336699; }
    </style>
{% endblock %}
{% block content %}
    <h1>Index</h1>
    <p class="important">
      Welcome to my awesome homepage.
    </p>
{% endblock %}
分享给朋友:
您可能感兴趣的文章:
随机阅读: