django templating system inheritance issue
i am having issues with my django templating system, i have a base.html file, which contains the content which will be common on all the web pages of the web site, the base.html file fetches some dynamic content, like the categories and the archives, which are passed to it by a python file, which fetches the categories and the archives data from a mysql database.
the issue when i inherit this base.html file in other html files like index.html:
{% extends "base.html" %}
and when when i call the main index URL for ex: http://mywebsite.开发者_运维技巧com/index/
the index page gets loaded, but the categories and the archives data that should get loaded from the base.html file does not.
what am i doing wrong, please help.
Most likely you have one (or both) of these issues:
The block in base.html is being overridden with a block in the index.html, and you haven't used
{{block.super}}
to include the content from the base template.The view function that invokes index.html isn't creating the proper context variables to give the template the data it needs.
As this is an old issue, it's probably been resolved by now, but I found an issue with Django 1.1 where template inheritance doesn't seem to work in certain situations.
My app is called 'budget'. Templates are in PROJECTROOT/budget/templates/budget, and I've defined my template directory as PROJECTROOT/budget/templates.
Inside the templates/budget directory I have base.html and index.html. index.html extends base.html via 'extends "budget/base.html"'.
When I hit the index url, the index.html template renders without inheriting from base.html. When I switched the naming of index.html to budget_index.html, everything worked as expected.
I hope this helps somebody, as I've been bashing my head against this for a few hours now.
精彩评论