Forums

TemplateDoesNotExist, cannot load template

if you need permission to access my account then yes you can, just reply me the solution

my template location->

/home/lnctgg/lnct/templates/index.html

settings.py->

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},
]
AUTH_USER_MODEL = 'CustomAuth.userLogin'
WSGI_APPLICATION = 'lnct.wsgi.application'

calling->

 return render(request, 'index.html')

error ->

Exception Type: TemplateDoesNotExist
Exception Value:    index.html
Exception Location: /home/lnctgg/.virtualenvs/virenv/lib/python3.7/site-packages/django/template/loader.py in get_template, line 19

&&&&

Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:

django.template.loaders.filesystem.Loader: /home/lnctgg/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/lnctgg/.virtualenvs/virenv/lib/python3.7/site-packages/django/contrib/admin/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/lnctgg/.virtualenvs/virenv/lib/python3.7/site-packages/django/contrib/auth/templates/index.html (Source does not exist)

As you can see from the template postmortem output, Django is looking in /home/lnctgg/templates, but you have your index file in /home/lnctgg/lnct/templates, so it cannot find it. From the code that you've posted, that suggests that your BASE_DIR is incorrect, since it should be /home/lnctgg/lnct, which would set your templates in the right place if the TEMPLATES DIRS key is [os.path.join(BASE_DIR, 'templates')]

I am having a similar problem. My Django web app works locally on Windows but it is not working on PA. The first login page loads but after logging in, I get a "Template Does Not Exist" error for the index.html which extends a layout2.html page that cannot be found. The login page extends a layout1.html page which is in the same directory below. I am not sure why layout1.html template is found but layout2.html is not being found.

my template location:

 /home/conordore/mma-client-portal/mma_dashboard/templates/mma_dashboard

Template-loader postmortem:

Django tried loading these templates, in this order:

Using engine django:

  • django.template.loaders.filesystem.Loader: /home/conordore/mma-client-portal/mma_dashboard/templates/mma_dashboard/layout2.html (Source does not exist)
  • django.template.loaders.app_directories.Loader: /home/conordore/.virtualenvs/venv/lib/python3.10/site-packages/django/contrib/admin/templates/mma_dashboard/layout2.html (Source does not exist)
  • django.template.loaders.app_directories.Loader: /home/conordore/.virtualenvs/venv/lib/python3.10/site-packages/django/contrib/auth/templates/mma_dashboard/layout2.html (Source does not exist)
  • django.template.loaders.app_directories.Loader: /home/conordore/mma-client-portal/mma_dashboard/templates/mma_dashboard/layout2.html (Source does not exist)

Error during template rendering

In template /home/conordore/mma-client-portal/mma_dashboard/templates/mma_dashboard/index.html, error at line 1

mma_dashboard/layout2.html

{% extends "mma_dashboard/layout2.html" %}

Here are parts of my settings.py file:

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mma_dashboard']

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': ['/home/conordore/mma-client-portal/mma_dashboard/templates'],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},
]

parts of views.py calling index.html:

return render(request, 'mma_dashboard/index.html', {
    "projects": projects,
    "user": request.user
})

start of index.html:

{% extends "mma_dashboard/layout2.html" %}

This is the start of my login page which works:

{% extends "mma_dashboard/layout1.html" %}

Both layout html pages are in the same template directory and layout1 is being found with the login page but layout2 is not being found by the index.html page.

Any help with this would be much appreciated.

Could it be problem with capital letters in filenames? Windows does not care about capitalization, Linux does.

That was it. I had a capital letter in one of my template html files. Thank you so much for the help!

Excellent, glad we could help!