I am working on chapter 4 of Django for Beginners by M Vincent. He suggests we create a project-level “templates” directory. Inside this directory should be the home.html. From my inexperienced point of view I think I have done just that. However when I run the development server I get a TemplateDoesNotExist error. What should I be doing.
This is my settings.py file
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [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",
],
},
},
]
The templates directory is on the same level as the django_project and the pages app
This is the traceback that I get
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 5.1.4
Python Version: 3.12.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pages']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template loader postmortem
Django tried loading these templates, in this order:
Using engine django:
* django.template.loaders.filesystem.Loader: C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\templates\home.htl (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\.venvcompany\Lib\site-packages\django\contrib\admin\templates\home.htl (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\.venvcompany\Lib\site-packages\django\contrib\auth\templates\home.htl (Source does not exist)
Traceback (most recent call last):
File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\.venvcompany\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\.venvcompany\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\pages\views.py", line 7, in home_page_view
return render(request, "home.htl")
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\.venvcompany\Lib\site-packages\django\shortcuts.py", line 25, in render
content = loader.render_to_string(template_name, context, request, using=using)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\.venvcompany\Lib\site-packages\django\template\loader.py", line 61, in render_to_string
template = get_template(template_name, using=using)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\company\.venvcompany\Lib\site-packages\django\template\loader.py", line 19, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception Type: TemplateDoesNotExist at /
Exception Value: home.htl