开发者

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 %}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜