I have a project with 2 apps
project/ blog/ templates/ index.html polls/ templates/ index.html project/ templates/ base.html index.html
Now i want that the two apps extends the projects base.html
. Is this the way to go? how it is possible and are there better solutions?
There is already an question which is handling this question, but it's only worth mentioning if you dont use split directories: Django project base template
tl;dr: I want to use split directories and want to know how to extend a base template from multiple apps without copying it to every app
The way I like to organize my Django Project is – Keeps all Django apps in apps folder, static files (scripts, js, CSS) in the static folder, HTML files in templates folder and images and media content in the media folder.
To configure the Django template system, go to the settings.py file and update the DIRS to the path of the templates folder. Generally, the templates folder is created and kept in the sample directory where manage.py lives. This templates folder contains all the templates you will create in different Django Apps.
Django comes with six built-in apps that we can examine.
The Django template language is Django's own template system. Until Django 1.8 it was the only built-in option available. It's a good template library even though it's fairly opinionated and sports a few idiosyncrasies.
In current Django (1.10) TEMPLATE_DIRS is deprecated, so:
templates
directory at the project root,In settings.py find TEMPLATES -> DIRS and add it like this:
TEMPLATES = [ { ... 'DIRS': [(os.path.join(BASE_DIR, 'templates')),], ... }
Add a base.html to that directory.
{% extends 'base.html' %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With