2
votes

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

My structure:

ROOT(pyshop)

  • polls
    • templates
      • polls
        • index.html (contains {% extends "base.html" %})
  • pyshop
    • templates
      • base.html

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?

1

1 Answers

2
votes

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.