Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend 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
        .....

The problem

I want to extend base.html in events.html

I tried with:

{% 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',

)
like image 476
BlackWhite Avatar asked Dec 05 '25 02:12

BlackWhite


1 Answers

Your TEMPLATE_DIR is set to project/templates, not project/templates/project.

Since there is no base.html in project/templates, Django returns an error.

You could either move base.html up to project/templates, or reference it by writing :

{% extends "project/base.html" %}
like image 157
Brachamul Avatar answered Dec 06 '25 17:12

Brachamul