jinja2模板继承示例不起作用

时间:2012-12-12 03:31:15

标签: google-app-engine django-templates jinja2

有人尝试过jinja2模板继承吗?样本只对我有用。

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 %}
        &copy; Copyright 2008 by <a href="http://domain.invalid/">you</a>.
        {% endblock %}
    </div>
</body>

index.html(子模板)

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

我的输出

enter image description here

我的问题: 1.页面标题是“索引”。它应该是“索引 - Mypage” 2.没有页脚

请帮忙!!!! 供参考:我使用的是最新的谷歌应用引擎,python 2.7,IDE是Visual Studio 2012 + Python for Visual Studio,KAY framework(从django和jinja2扩展)

views.py

def index(request):
    return render_to_response('myapp/index.html')

1 个答案:

答案 0 :(得分:2)

Jinja2遵循TEMPLATE_DIRS设置的继承。我假设你的路径不正确。尝试:

{% extends "myapp/base.html" %}