4

I have several webpages that are identical except for the main content and the page title. The individual pages extend the base.html, which, among other things, contains the head and title.

The question is, is there some way to pass the title UP from the individual page to the parent? I've tried to illustrate below what it is I'd like.

base.html

<html>
   <head>
      <title>the_title</title>
   </head>
   <body>
      {% block content %}{% endblock %}
</body></html>

page1.html

{% extends "base.html" using "Page One" as the_title %}
{% block content %}Page 1 content{% endblock %}

I realize that I could pass the title from the view and just use it as {{the_title}}, but I really feel that the title should be written in the html, not the view logic.

4

1 回答 1

2

您可以使用标准的 Djangoblock模板标签

base.html

<html>
   <head>
      <title>{% block title %}base title{% endblock %}</title>
   </head>
   <body>
      {% block content %}{% endblock %}
</body></html>

child.html

{% extends "base.html" %}
{% block title %}child title{% endblock %}
{% block content %}Page 1 content{% endblock %}
于 2013-07-25T09:14:38.717 回答