TemplateDoesNotExist in Django views

Question:

I’m new to Django, currently following the tutorial on the Django site for polls:
https://docs.djangoproject.com/en/4.1/intro/tutorial03/

I’m not able to render my template when using polls/index.html. I have followed along verbatim, yet when i try to render the request in the views.py file, I am getting a TemplateDoesNotExist error, which states that the source is not found. What I don’t understand is my index.html is located in the correct location (IE, mysite > polls > template > polls > index.html) and my main settings are exactly how the tutorial states. I’ve tried the frequently suggested (if dated) response of adding os.path.join(SETTINGS_PATH, 'templates'), however the issue persists.

I’m currently running Python 3.10 with Django 4.1, yet this shouldn’t be the problem. I’ve confirmed that my index.html file is in the correct location, being stored in templates > polls > index.html.

settings.py


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',
            ],
        },
    },
]

views.py

import requests  
from .models import Question
from django.http import HttpResponse
from django.template.loader import get_template
# Create your views here.


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    context = {'latest_question_list': latest_question_list}
    return render(request, 'polls/index.html', context)

Error

polls/index.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/polls/
Django Version: 4.1
Exception Type: TemplateDoesNotExist
Exception Value:    
polls/index.html
Exception Location: C:Userspatbcmyprojectlibsite-packagesdjangotemplateloader.py, line 19, in get_template
Raised during:  polls.views.index
Python Executable:  C:UserspatbcmyprojectScriptspython.exe
Python Version: 3.10.4
Python Path:    
['C:\Users\patbc\myproject\mytestsite',
 'C:\Python310\python310.zip',
 'C:\Python310\DLLs',
 'C:\Python310\lib',
 'C:\Python310',
 'C:\Users\patbc\myproject',
 'C:\Users\patbc\myproject\lib\site-packages']
Server time:    Tue, 23 Aug 2022 20:33:42 +0000

Here is my directory structure (note that index.html resides in the proper subdirectory, ‘polls’):
link

Asked By: b0tchd

||

Answers:

You have named the folder wrong. It should be plural – templates, not template.

Answered By: NixonSparrow