Reputation: 4038
Anybody successful on trying jinja2 template inheritance? The sample just work partially for me.
base.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{% block head %}
<link rel="stylesheet" href="style.css" />
<title>{% block title %}{% endblock %} - My Webpage</title>
{% endblock %}
</head>
<body>
<div id="content">{% block content %}{% endblock %}</div>
<div id="footer">
{% block footer %}
© Copyright 2008 by <a href="http://domain.invalid/">you</a>.
{% endblock %}
</div>
</body>
index.html (child template)
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
{{ super() }}
<style type="text/css">
.important { color: #336699; }
</style>
{% endblock %}
{% block content %}
<h1>Index</h1>
<p class="important">
Welcome on my awesome homepage.
</p>
{% endblock %}
My output
My problem: 1. page title is "Index". It should be "Index - Mypage" 2. No footer
Please help!!!! For reference: I am using most updated google app engine, python 2.7, IDE is Visual studio 2012 + Python for Visual Studio, KAY framework (extended from django and jinja2)
views.py
def index(request):
return render_to_response('myapp/index.html')
Upvotes: 3
Views: 3510
Reputation: 1595
Jinja2 follows inheritance from your TEMPLATE_DIRS settings. I'm assuming that you have an incorrect path. Try:
{% extends "myapp/base.html" %}
Upvotes: 3