Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django extends problem - the child template is not showing

I've already configured the necessary things to work the extends template function in django. here's my codes:

in settings.py

def my_dir():
    import os.path
    return os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIRS = ( my_dir() + '/app/templates', ) #dynamic template directory

in base.html - located in app/templates/site

....
<div id="SideBar" class="FloatLeft">
{% block sidebar %} {% endblock %}
</div>
....

in sidebar.html - located in app/templates/site

{% extends "site/base.html" %}
{% block sidebar %}
   some code here
{% endblock %}

I've tried also the {% include "site/sidebar.html"%} tag in the base.html to check the template directory, and yes include tag is working...

what's the problem in the {% extends %} ? why does it doesnt detect its parent template..

please help me guys.. your help is greatly appreciated... im still waiting for the answer.. tnx

like image 740
EVG Avatar asked Oct 31 '10 01:10

EVG


2 Answers

Which template are you rendering in your view? It should be the child, not the parent.

like image 170
Daniel Roseman Avatar answered Sep 18 '22 15:09

Daniel Roseman


I am not sure what yout problem is, but you should check the following points :

  • The {% extends %} tage should be the first one in the template file (and put a blank line afterwards to be sure)
  • I think that the reference to the base template is relative to you TEMPLATE_DIR. Try different things like putting both templates at the same level etc.
  • Check all the tags in both templates to be sure that they are all correctly formatted
  • Check the encoding of the files. If it is UTF-8, try to disable the BOM in both files.
  • Maybe it is a problem with your directory setting. Try to hard code the absolute path to check that.

These are the problems I can imagine, but I can't guarantee that it will work.

like image 35
Marc Demierre Avatar answered Sep 17 '22 15:09

Marc Demierre