Django:关于模板继承的问题

时间:2011-05-16 11:04:15

标签: python html django templates

您好我似乎遇到了使用基本模板的问题。我的基本html称为help_content.html。

<html>
<head>
    <meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8">
    <a href="help_new_client.html">New Client</a>
    <title>User Manual</title>
    <style></style></head>
<body style="padding:10px;">
    {% block content %}{% endblock %}
</body>
</html>

这是我的名为help_new_client.html的儿童模板

{% extends "help_content.html" %}
{% block content %}
<h3 class="western">New  Client</h3>
<p><b>Add client</b></p>
<p>If you are not already on the All clients screen then click “VIEW
CLIENTS” on the main menu.</p>
<p>Click on the Add client button. A Client form is displayed. Fill
the form and click save.</p>
<p>Action: VIEW CLIENTS → Add client → save</p>
<p><b>Edit client</b></p>
<p>To edit a  client simply click on the client in the All clients
list. Edit the clients information and save.</p>
<p>Action: VIEW CLIENT → click on client → click on Edit client
information → save 
</p>

{% endblock %}

编辑:观看次数

@login_required
def help_index(request):
    return render_to_response('help_content.html', context_instance=RequestContext(request))

@login_required
def help_new_client(request):
    return render_to_response('help_new_client.html', context_instance=RequestContext(request))

我不确定我做错了什么。在help_content.html中,我看到{% block content %}{% endblock %},在help_new_client.html中,我看到{% extends "help_content.html" %} {% block content %} {% endblock %}。我不确定为什么我收到这些模板标签而不是我的内容。

2 个答案:

答案 0 :(得分:0)

我猜你没有从视图中渲染模板。

您确定在视图中执行此类操作,并且您是通过相应的网址格式执行该视图:

from django.template import RequestContext
from django.shortcuts import render_to_response
def index(request):
    return render_to_response('help_content.html',
                      context_instance=RequestContext(request))

我在扩展模板中没有看到这是第一行:

{% extends 'help_content.html' %}

并关闭基本模板中的</body>标记,以确定。

答案 1 :(得分:0)

我在模板文件夹中有我的基本模板。我有我所有其他模板的子文件夹。

view.py

from django.shortcuts import render_to_response;
def help_index(request):
    return render_to_response('html-template/help_new_client.html')

在你的情况下它将是

return render_to_response('help_new_client.html')