Django: template inheritance override on include
For example I have top.html
which will be incl开发者_如何学Cuded from within base.html
.
How to override contents of top.html
after including?
You didn't understand templates idealogy.
Right way is create base.html like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Some app - {% block header %}{% endblock %}</title>
</head>
<body>
<h1>{% block title %}Default title{% endblock %}</h1>
{% block content %}{% endblock %}
</body>
</html>
And then in page.html you can override header for example:
{% extends "base.html" %}
{% block title %}Some page{% endblock %}
{% block header %}Overriden header{% endblock %}
{% block content %}
Some content
{% endblock %}
精彩评论