Forums

TemplateDoesNotExist at /

t

If you're seeing that error on your website, then it will list the directories where it looked for the template; you can check those directories to see whether the template is actually there. One thing to look out for if you've previously been developing your website on a Windows computer is that Linux filesystems like the one on PythonAnywhere are case-sensitive, so if you called your template "Something.html" and you're trying to access it in your code as "something.html", then it won't be able to find it -- just rename the template so that its case matches the one you use in the code, and it should work fine.

I am trying to develop a site using Django, but when I attempt to open the home page on my browser, it is reporting a TemplateDoesNotExist error:

TemplateDoesNotExist at /

/reviews/index.html

I have a template named index.html in a subfolder in my app named templates/reviews/.

The template-loader postmortem reports the following:

Django tried loading these templates, in this order:

Using engine django:

    This engine did not provide a list of tried templates.

It seems that Django doesn't even know where to look for templates. This is despite the fact that TEMPLATES is defined in my settings.py file as follows:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

I have the same TEMPLATES settings on my local PC so I cannot understand why my PythonAnywhere setup cannot find the templates. Can anyone help me? I am using Python 3.8.10 and Django 4.1.3.

Try populating the DIRS entry with paths to the template dirs and reload the web app.

I've added the template directory to the DIRS field in the TEMPLATES setting but exactly the same error message appears. :-( I'm beginning to feel that I may just have to delete the lot and start again - although I have a full copy of the site on my local PC.

Make sure that the path you used in DIRS is correct and corresponds to the file structure you have on PythonAnywhere (use absolute path). Also, remember to reload the web app, after making those changes.

No, still no joy. I've tried changing DIRS to something like ["/home/cpcgamereviews/mysite/myapp/templates/"], and the directory definitely exists in my file structure, but the same TemplateDoesNotExist error message still appears even after reloading the web app.

If you refer to it as /reviews/index.html that would not work as it is absolute path that starts with root / directory. Remove the initial /.

That's solved the issue. Thanks fjl! It's a bit surprising how many things work in manage.py runserver mode on my local PC that don't quite work once I upload the files to PythonAnywhere's servers. I'm still finding my way around slowly. :-)