Basic template for all applications in Django

I have a project with 2 applications

project/
    blog/
        templates/
            index.html
    polls/
        templates/
            index.html
    project/
        templates/
            base.html
            index.html

Now I want two applications to expand projects base.html. Is that the way? how is this possible and are there better solutions?

A question has already been asked that handles this question, but it is worth mentioning if you dont use shared directories: Django project database template

tl; dr: I want to use shared directories and want to know how to extend the base template from multiple applications without copying it to each application.

+4
source share
3 answers

Django (1.10) TEMPLATE_DIRS , :

  • templates ,
  • settings.py TEMPLATES → DIRS :

    TEMPLATES = [
    {
        ...
        'DIRS': [(os.path.join(BASE_DIR, 'templates')),],
        ...
    }
    
  • base.html .

  • , , {% extends 'base.html' %}
+14
  • templates TEMPLATE_DIRS.
  • base.html .
  • , , {% extends 'base.html' %}
+6

Django 1.8 upgrade doc ( -, ) settings.py:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [(os.path.join(BASE_DIR, 'my_Templates_Directory')),],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
                # list if you haven't customized them:
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

BACKEND, OPTIONS, , "INVALID BACKEND", "django.contrib.auth.context_processors.auth" TEMPLATES ".

+1

All Articles