2012-10-09 115 views
1

我在我的应用程序中使用Django模板系统,并在子模板中相应地引用了{%extends“base.html”%},虽然在重新调整模板时,它只会出现html标签而没有CSS样式 - 因此完全没有选择base.html模板。 请告诉我我做错了什么?它可能是一个问题,它没有找到我的base.html模板的位置?Django-Child template-Base.html不渲染

这是孩子模板代码:

{% extends "base.html" %} 
{% block content %} 
{% for field in form %} 
{{ form }} 
{% endfor %} 
{% endblock %} 

这是base.html文件模板代码(相关部分):

<div id="content"> 
<h2> 
       Page heading - This is where the functionality goes... 
      </h2> 
      <FIELDSET><INPUT class=Test value="Test" type=submit></FIELDSET> 

      {% block primary %}{% endblock %} 
</div> 

请让我知道如果你需要任何firther信息来解决这个问题。

-I将添加views.py今晚(伦敦时间) -

这一切都解决,非常感谢您的帮助

感谢

+0

如果您缺少样式(CSS)并且它们驻留在STATIC文件夹中,则可能是问题所在。 – Jingo

+0

基本模板是否自行工作(正确渲染,包括CSS)? –

+1

为什么你为每个表单域渲染相同的表单? –

回答

0

就像提到goliney .. 。 你需要有

{% block content %} 
{% endblock %} 

你base.html文件的文件有一个部分,那么你可以覆盖在扩展base.html模板的其他模板中。

目前在你的孩子的模板,你可以做一个

{% block primary %} 
whatever you want here and this would show up where you marked on the base.html template 
{% endblock %} 

而且不知道如果你是刚刚组建了一个简单的例子与否。您将需要创建

<form action="" method="post">{% csrf_token %} 
for loop here 
</form>