Sergey Zakatov
Sergey Zakatov

Reputation: 23

Django Template inheritance (location for extends)

I'm trying to create base.html to extend it from my apps.

My structure:

ROOT(pyshop)

But it can't find base.html

Template-loader postmortem

Django tried loading these templates, in this order:

Using engine django: django.template.loaders.app_directories.Loader: /home/sz/Projects/pyshop/polls/templates/pyshop/base.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/sz/Projects/pyshop/venv/lib/python3.5/site-packages/django/contrib/admin/templates/pyshop/base.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/sz/Projects/pyshop/venv/lib/python3.5/site-packages/django/contrib/auth/templates/pyshop/base.html (Source does not exist)

Any suggestions?

Upvotes: 2

Views: 286

Answers (1)

Alasdair
Alasdair

Reputation: 309109

Your pyshop/pyshop/templates directory will not be searched by the app directories loader, because it is not an app. The usual approach is to add this directory to the DIRS list.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'pyshop', 'templates'),]
    ...
    }
]

Secondly, the traceback makes it looks as if you are doing {% extends "pyshop/base.html" %}, not {% extends "base.html" %} as in your question. If you have {% extends "base.html" %}, then you will need to move your base.html template to pyshop/pyshop/templates/pyshop/base.html.

Upvotes: 2

Related Questions