TemplateDoesNotExist at / basicapp/index.html

`Hello friends,i tried creating basic forms with django from a direct example from Python and Django Full Stack Web Developer Bootcamp. i got the error below.

TemplateDoesNotExist at / basicapp/index.html Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 4.1.3 Exception Type: TemplateDoesNotExist Exception Value:
basicapp/index.html Exception Location: C:\Users\ADMIN\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\template\loader.py, line 19, in get_template Raised during: basicapp.views.index Python Executable: C:\Users\ADMIN\AppData\Local\Programs\Python\Python311\python.exe

Python Version: 3.11.0

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

Using engine django:

django.template.loaders.filesystem.Loader: C:\Users\ADMIN\Desktop\Django\Django_forms\basic_forms\templates,\basicapp\index.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\ADMIN\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\admin\templates\basicapp\index.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\ADMIN\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\templates\basicapp\index.html (Source does not exist)

This is my **setting.py **

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATE_DIR = os.path.join(BASE_DIR,"templates,")


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-bdh2@$^s84&+%qn^atqa+xjz8@7&g=(m2^!5j$f#$o=4+7jb5s'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

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

    "basicapp",
]

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

ROOT_URLCONF = 'basic_forms.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIR],
        'APP_DIRS': True,`




**View.py**

from django.shortcuts import render from . import forms

Create your views here.

def index(request):
    return render(request,"basicapp/index.html")


def form_name_view(request):
    form = forms.FormName()

return render(request,"basicapp/form_page.html",{"form:Form":form})
**Urls.py**

from django.contrib import admin from django.urls import path from basicapp import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path("", views.index,name="index"),
    path("formpage/", views.form_name_view, name="form_name"),
]
**forms.py**

from django import forms

class FormName(forms.Form): name=forms.CharField()` email=forms.EmailField() text=forms.CharField(widget=forms.Textarea)

`

You got templates does not exist because you have added comma in TEMPLATE_DIR.

TEMPLATE_DIR = os.path.join(BASE_DIR,"templates") #let's remove comma from here.

And now this will work!

Back to Top