Reputation: 4473
I have a view that returns a page from my template dir, successfully, no problem:
def home(request):
c = {}
return render_to_response('home.html', c, context_instance=RequestContext(request))
If home.html is a simple webpage with no extends, it returns fine.
However, if I use an include, say {% extends "base.html" %}, it simply returns the base.html without adding in the content from the child home.html. What could be causing this?
home.html
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
This is the homepage.
{% endblock %}
base.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{% block content %}{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
At the moment, this is returning a copy of base.html like this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
</body>
</html>
Why is it not including the content or title block?
Upvotes: 0
Views: 138
Reputation: 53326
In your base.html block named content is appearing twice. You may want to name first block as title
e.g. {% block title %}{% endblock %}
Django recommends that you shouldn't define multiple template blocks with same name.
From Template inheritance
Finally, note that you can't define multiple block tags with the same name in the same template. This limitation exists because a block tag works in "both" directions. That is, a block tag doesn't just provide a hole to fill -- it also defines the content that fills the hole in the parent. If there were two similarly-named block tags in a template, that template's parent wouldn't know which one of the blocks' content to use.
Upvotes: 1