[Django]-Django Footer and header on each page with {% extends }

35👍

You need to define a block in base.html and populate it in about.html.

base.html:

<header>...</header>
{% block content %}{% endblock %}
<footer>...</footer>

about.html

{% extends "public/base.html" %}

{% block content %}
<h1>Content goes here</h1>
{% endblock %}

This is all fully explained in the tutorial.

12👍

{% extends "public/base.html" %}
{% block content %}
<h1>Content goes here</h1>
{% endblock %}

Or simply create about.html and include it where you want in your main html.

Example:

    {% extends "public/base.html" %}
    {% block content %}
       "Your code"
    {% include "core/about.html" %}
    {% endblock %}
👤chandu

2👍

Let’s say your base.html looks like this:

<html>
    <body>
        <!-- header code -->
        {% block content %}
        {% endblock %}
        <!-- footer code -->
    </body>
<html>

Then in your other file you would do this:

{% extends "base.html" %}
{% block content %}
    <!-- Content here -->
{% endblock %}

Anything placed inside the template’s (extended file’s) body tag would be overwritten by the stuff in the child file’s content, but anything outside of that tag would be extended, or copied, into it.

Here are the docs on the block tag

Leave a comment