How do I fix Django TemplateDoesNotExist at /?

Question:

I reinstall windows on my computer, after I install Python 3.8.3 and Django 3.0.7, anaconda, visual studio code, and a lot of shit.
When I continue with my project, I follow my tutorial made some changes and after running the server I found with this error.
After going back to what I think what I was the last time It works, I reinstall everything again thinking that maybe was some mistake on the installation.

I tried with the templates DIRS too and I got the same error.

The place where my templates are is F:ProgramacionPythonDjangoProyectoWebProyectoWebApptemplatesProyetoWebApp

TemplateDoesNotExist at /
ProyectoWebApp/Inicio.html

Request Method:     GET
Request URL:    http://127.0.0.1:8000/
Django Version:     3.0.7
Exception Type:     TemplateDoesNotExist
Exception Value:    

ProyectoWebApp/Inicio.html

Exception Location:     D:Pythonlibsite-packagesdjangotemplateloader.py in get_template, line 19
Python Executable:  D:Pythonpython.exe
Python Version:     3.8.3
Python Path:    

['F:\Programacion\Python\Django\ProyectoWeb',
 'D:\Python\python38.zip',
 'D:\Python\DLLs',
 'D:\Python\lib',
 'D:\Python',
 'C:\Users\frua\AppData\Roaming\Python\Python38\site-packages',
 'D:\Python\lib\site-packages']
Server time:    Sun, 7 Jun 2020 19:23:51 +0000


Template-loader postmortem

Django tried loading these templates, in this order:

Using engine django:

    django.template.loaders.filesystem.Loader: F:ProgramacionPythonDjangoProyectoWebProyectoWebApptemplateProyectoWebAppInicio.html (Source does not exist)
    django.template.loaders.app_directories.Loader: D:Pythonlibsite-packagesdjangocontribadmintemplatesProyectoWebAppInicio.html (Source does not exist)
    django.template.loaders.app_directories.Loader: D:Pythonlibsite-packagesdjangocontribauthtemplatesProyectoWebAppInicio.html (Source does not exist)

My view:

from django.shortcuts import render, HttpResponse

# Create your views here.


def Inicio (request):

    return render(request, "ProyectoWebApp/Inicio.html")

def Servicios (request):

    return render(request, "ProyectoWebApp/Servicios.html")

def PortFolio (request):

    return render(request, "ProyectoWebApp/PortFolio.html")

def Blog (request):

    return render(request, "ProyectoWebApp/Blog.html")

def Contacto (request):

    return render(request, "ProyectoWebApp/Contacto.html")

My settings.py

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'm@!i1+f$%8ce#eu%_to13z@z=w=zmzz2)_a2juj!hzu13^j%)='

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

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 = 'ProyectoWeb.urls'

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

WSGI_APPLICATION = 'ProyectoWeb.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
Asked By: CabraSerrana

||

Answers:

I have run into this kind of problems sometimes (not this in particular), you can try to change in setting.py under template section the folder where you will be taking the templates, adding a path using os library

Answered By: Daniele Compagnoni

After starting again my project to see where the problem where I found it…

It could not be something simpler…

The place where my templates are is F:ProgramacionPythonDjangoProyectoWebProyectoWebApptemplatesProyetoWebApp

It was a typing error… When I create the folder with my templates I wrote something diferent that when i created the path in the views of the project.

The place where my templates are is F:ProgramacionPythonDjangoProyectoWebProyectoWebApptemplatesProyectoWebApp

Answered By: CabraSerrana

The easiest way to fix that error is to go to your settings.py file, scroll to TEMPLATES
Open

‘DIRS’: [],

Go back to your template file location on the project, copy the path/reference location of your template file, go back to settings.py
paste the path/reference as below:

Open ‘DIRS’: [r’C:UsersstackPycharmProjectsfile_tutorial’],

then refresh your page.

Answered By: Joshy