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 %}
- [Django]-Using django-admin on windows powershell
- [Django]-Allowing RabbitMQ-Server Connections
- [Django]-Django-taggit – how do I display the tags related to each record
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
- [Django]-Django – No module named _sqlite3
- [Django]-Django admin default filter
- [Django]-Create a field whose value is a calculation of other fields' values
Source:stackexchange.com