2011-05-16 145 views
0

你好我似乎有一个使用基本模板的问题。我的基本html被称为help_content.html。Django:关于模板继承的问题

<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 %}。我不确定为什么我收到这些模板标签而不是我的内容。

+0

显示您的看法! – 2011-05-16 11:58:39

回答

0

我想你不是从视图中呈现模板。

你确定你正在做这样的事情的看法,并认为您是通过相应的URL模式执行这一观点:

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)) 

我没有在你的扩展模板认为这是第一line:

{% extends 'help_content.html' %} 

并关闭您的基本模板中的</body>标记只是为了确保。

+0

由于某些原因,仍然无法正常工作。我为基本和子模板创建了一个视图,并将它们的链接放在了urls.py文件中。所以仍然和以前一样。 – Shehzad009 2011-05-16 11:58:57

+0

@ Shehzad009我已经更新了我的答案。看看是否有效 – 2011-05-16 12:13:37

+0

我的模板中有{%extends“help_content.html”%}“。我删除了编辑过的身体标记,但仍然存在问题。 – Shehzad009 2011-05-16 12:32:08

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')