I'm trying to add a base template for use in different apps in my Django project. I've created a base.html file at "myapp/templates/base.html"
Here is the relevant info in my settings.py:
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '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',
],
},
},
]
When I try to load the view in my browser, I get a this error:
TemplateDoesNotExist at /home/
base.html
Request Method: GET
Request URL: http://127.0.0.1:8000/home/
Django Version: 3.1.1
Exception Type: TemplateDoesNotExist
Exception Value:
base.html
Exception Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/template/backends/django.py, line 84, in reraise
Python Executable: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
Python Version: 3.8.5
Python Path:
['/Users/jonmi/PycharmProjects/projects/grocery',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
Server time: Sun, 13 Dec 2020 01:43:02 +0000
As I understand it, the template loader should look in each of my installed_apps' template directories since APP_DIRS is set to True, and it should also look in any directory in the DIRS list. However, the template loader is only looking in the app directories (e.g. myapp/home/templates/home/base.html) and not in anything I add to the DIRS list.
I've tried changing whats in the DIRS list, including just trying to type out the path to base.html as a string myself, but it doesn't check anything I add to the list.
I've seen similar questions asked, but they are all for older versions of Django, and the solutions they've provided did not work for me. There are lots of people who have had the TemplateDoesNotExist error, but this is the question I've found most similar to mine: Django 1.8 ignores DIRS, cannot find templates
However, the solutions posted there did not help me, and the question is about a much older version of Django.
How can I get the template loader to look at what's in the DIRS list?
EDIT:
In trying to add some more info to my question, I figured out what was wrong. I had copy and pasted the TEMPLATES settings from another stackoverflow question into my settings.py, but I hadn't overwritten the old TEMPLATES settings, so they were getting switched back to my initial settings since my old settings were further down in my code.
If you're having this problem, the TEMPLATES settings in my question do indeed work properly.
Thanks to whoever read and commented.