Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django template extends not working

This is my base.html

<!DOCTYPE html> 
<head> 
<title> My Site </title>
</head> 
<body>
<div id="wrapper">  
<!-- HEADER START -->
{% block nav %} {% endblock %}
{% block index %} {% endblock %}
</div> 
</body>
</html>

this is my nav.html

{% extends "base.html" %}
{% block nav %}
<div id="header"> 
<div class="inner">

<div class="nav"> 
<ul> 
<li class="current"><a href="index.html">Home</a></li> 
<li><a href="about.html">About</a></li> 
<li><a href="blog_right.html">Blog</a></li>                        
<li><a href="contact.html">Contact</a></li> 
</ul>                     
</div>  
<div class="clear"></div>           
</div><!-- .inner end --> 
</div><!-- #header end --> 
<!-- HEADER END -->
{% endblock %}

this is my index.html

{% extends "base.html" %}
{% block index %}
<p> hello </p>
{% endblock %}

I have done it several times before before but i am clueless as to why this is NOT working? the urls and views are here.

like image 207
user993563 Avatar asked Dec 31 '11 14:12

user993563


1 Answers

Well everything is fine, the trouble that you are having is that you are confused, just naming a block in base does not calls it. Mark the difference between extends and include. You have counfused extends to include.

Once in your views if you call say index.html it will be rendered properly. The effect you want can be achieved by changing the base.html in your views to index.html.

Hope this helps. more can be read here: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance

like image 65
whatf Avatar answered Oct 24 '22 22:10

whatf