O'Reilly logo

Django 1.0 Web Site Development by Ayman Hourieh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Improving template structure

We have created three templates so far. They all share the same general structure, and only differ in the title and main content. Wouldn't it be great if we could factor out the shared sections into a single file so that if we want to modify all the pages in future, we will need to edit only one file?

Fortunately, the Django template system already provides such a feature-template inheritance. The idea is simple. We create a base template that contains the structure shared by all templates in the system. We also declare certain blocks of the base template so that they can be modified by child templates. Next, we create a template that extends the base template and modifies its blocks. The idea is very similar to class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required