hi all, I tried to build Django page using this post: djangocentral.com/building-a-blog-application-with-django/ Seems I completed all steps but I am getting this error when running server. Do you know what can be reason for error message I am getting?
TemplateDoesNotExist at /
index.html, blog/post_list.html
Request Method: GET
Request URL: http://127.0.0.1:8080/
Django Version: 3.2.9
Exception Type: TemplateDoesNotExist
Exception Value:
index.html, blog/post_list.html
Exception Location: C:\Download\Development\NowaStrona_Django\lib\site-packages\django\template\loader.py, line 47, in select_template
Python Executable: C:\Download\Development\NowaStrona_Django\Scripts\python.exe
Python Version: 3.7.3
Python Path:
['C:\\Download\\Development\\NowaStrona_Django\\mysite\\my_site',
'C:\\Download\\Development\\NowaStrona_Django\\Scripts\\python37.zip',
'C:\\Download\\Development\\NowaStrona_Django\\DLLs',
'C:\\Download\\Development\\NowaStrona_Django\\lib',
'C:\\Download\\Development\\NowaStrona_Django\\Scripts',
'c:\\program files (x86)\\python37-32\\Lib',
'c:\\program files (x86)\\python37-32\\DLLs',
'C:\\Download\\Development\\NowaStrona_Django',
'C:\\Download\\Development\\NowaStrona_Django\\lib\\site-packages']
Server time: Wed, 15 Dec 2021 10:54:46 0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\T\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\E\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\M\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\P\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\L\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\A\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\T\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\E\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\S\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\_\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\D\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\I\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\R\index.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\S\index.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Download\Development\NowaStrona_Django\lib\site-packages\django\contrib\admin\templates\index.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Download\Development\NowaStrona_Django\lib\site-packages\django\contrib\auth\templates\index.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\blog\templates\index.html (Source does not exist)
Using engine django:
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\T\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\E\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\M\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\P\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\L\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\A\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\T\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\E\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\S\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\_\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\D\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\I\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\R\blog\post_list.html (Source does not exist)
django.template.loaders.filesystem.Loader: C:\Download\Development\NowaStrona_Django\mysite\my_site\S\blog\post_list.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Download\Development\NowaStrona_Django\lib\site-packages\django\contrib\admin\templates\blog\post_list.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Download\Development\NowaStrona_Django\lib\site-packages\django\contrib\auth\templates\blog\post_list.html (Source doe
I am also attaching SETTINGS file which was used:
"""
Django settings for my_site project.
Generated by 'django-admin startproject' using Django 3.2.9.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES_DIRS = os.path.join(BASE_DIR,'templates')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-pt0&^4*xfh$-0dmwo$n-y=h@hvelr ^wyvhha=s3=z27#cirp4'
# 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',
'blog',
]
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 = 'my_site.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': 'TEMPLATES_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 = 'my_site.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/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.2/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.2/howto/static-files/
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
I am running server locally, and also I am beginner with this.
CodePudding user response:
Go to your app called "post" and search for a template folder, if you cannot find it maybe you have a template folder with a subfolder call "post".
Inside of it add a new file call : post_list.html
CodePudding user response:
It seems like your template configuration is not correct
in your settings.py change this line
'DIRS': 'TEMPLATES_DIRS',
to
'DIRS': ['templates/'],
CodePudding user response:
Your template configuration is incorrect you can configure it like this
method 1
#easy and recomended for latest version of django
BASE_DIR = Path(__file__).resolve().parent.parent
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',
],
},
},
]
method 2
you've to put your TEMPLATES_DIRS without single or double quotes if you put quotes than it will treated as string not a variable so change like this
'DIRS': [TEMPLATES_DIRS],
Note:
DIRS defines a list of directories where the engine should look for template source files, in search order.