base.html:
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}My Website{% endblock %}</title>
</head>
<body>
<header>
<h1>{% block header %}Default Header{% endblock %}</h1>
</header>
<div class="content">
{% block content %}
{% endblock %}
</div>
</body>
</html>
In your specific templates that inherit from base.html, you can override the header block and set the appropriate header tag content based on the route URL. Here's an example for two different routes:
home.html:
{% extends 'base.html' %}
{% block header %}
<h1>Welcome to My Website</h1>
{% endblock %}
{% block content %}
<!-- Content for the home page -->
{% endblock %}
about.html:
{% extends 'base.html' %}
{% block header %}
<h1>About Us</h1>
{% endblock %}
{% block content %}
<!-- Content for the about page -->
{% endblock %}
Top comments (0)