I'm working on a Django site that has multiple sections and subsections. I'd like to have several depths of template inheritance: a base template for the whole site, one base template for each section that inherits from the root base template, and so on. Here's a simplified version of my desired directory structure:
base.html
section1/
base.html
section2/
base.html
section3/
base.html
What I would desire is for all the files under section1/
to contain something like {% extends "base.html" %}
, meaning they would extend section1/base.html
. section1/base.html
would contain something like {% extends "../base.html" %}
, meaning that it would extend the root-level base file. However, I couldn't find anything in the documentation suggesting this was possible, and I couldn't get Django to distinguish between "../base.html"
and "base.html"
. ({% extends "../base.html" %}
throws an error.) I suppose one workaround would be to rename all base files base_SECTIONNAME.html
, and update all the files that inherit from them, but I am concerned that this might become difficult to maintain as my site becomes bigger and sections change names, etc. I would prefer a solution that takes advantage of the natural hierarchy specified by directories and subdirectories.
Any ideas?