How do I extend a template from another module?

I have a project with the following structure:

project    
    project
        static/
        templates
            project
                base.html
        __init__.py
        .....
    events
        static/
        templates
            events
                events.html
        __init__.py
        models.py
        .....

      

Problem

I want to expand base.html

intoevents.html

I tried:

{% extends "project:project/base.html" %}

      

But get the following error :

Exception Type:     TemplateDoesNotExist
Exception Value:    project:project/base.html

      

Also tried with:

{% extends "base.html" %}

      

But the same error is returned :

Exception Type:     TemplateDoesNotExist
Exception Value:    base.html

      

In INSTALLED_APPS

I have:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'events',
    'project',
)

      

TEMPLATE_DIRS

and BASE_DIR

:

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

      

In TEMPLATE_LOADERS

I have:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',

)

      

+3


source to share


1 answer


Yours is TEMPLATE_DIR

set to project/templates

, not project/templates/project

.

Since project/templates

no base.html

, Django returns an error.



You can either move base.html

to project/templates

or reference it by writing:

{% extends "project/base.html" %}

      

+1


source







All Articles