I am trying to release my website to a staging environment but I keep get TemplateDoesNotExist error. My website consists of multiple apps that will extend a base app for common elements. When I view the website in a development environment it works as expected, however when I try to view it in my staging environment it errors out.
All of the templates in the apps, other than the base templates, contains {% extends "main/index.html "%} at the top of them.
file structure:
├── manage.py
├── assets
├── base
│ ├── templates
│ │ ├── main
│ │ │ ├── index.html
│ ├── urls.py
│ ├── views.py
│ ├── ...
├── dashboard
├── inventory
│ ├── templates
│ │ ├── main
│ │ │ ├── inventory.html
│ ├── urls.py
│ ├── views.py
│ ├── ...
├── magic
│ ├── templates
│ │ ├── main
│ │ │ ├── sets.html
│ │ │ ├── cards.html
│ ├── urls.py
│ ├── views.py
│ ├── ...
├── website
│ ├── settings
│ │ ├── base.py
│ │ ├── staging.py
│ │ └── production.py
│ ├── asgi.py
│ ├── urls.py
│ └── wsgi.py
settings/base.py:
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent.parent
SECRET_KEY = ''
DEBUG = True
ALLOWED_HOSTS = [
'localhost',
'0.0.0.0',
'127.0.0.1',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'base.apps.BaseConfig',
'dashboard.apps.DashboardConfig',
'inventory.apps.InventoryConfig',
'magic.apps.MagicConfig',
'django_filters',
'psycopg2',
]
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 = 'website.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(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',
],
},
},
]
WSGI_APPLICATION = 'website.wsgi.application'
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'development',
'USER': 'superuser',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
# Password validation
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
LANGUAGE_CODE = 'en-gb'
TIME_ZONE = 'Europe/London'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets')]
settings/staging.py:
import dj_database_url
from .base import *
SECRET_KEY = os.environ.get('SECRET_KEY')
DEBUG = True
ALLOWED_HOSTS += [
'staging.herokuapp.com',
]
INSTALLED_APPS += [
'whitenoise.runserver_nostatic',
]
MIDDLEWARE += [
'whitenoise.middleware.WhiteNoiseMiddleware',
]
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets')]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Error:
TemplateDoesNotExist at /magic/sets/
main/index.html
Request Method: GET
Request URL: https://card-crate-admin-staging.herokuapp.com/magic/sets/
Django Version: 3.1.5
Exception Type: TemplateDoesNotExist
Exception Value:
main/index.html
Exception Location: /app/.heroku/python/lib/python3.7/site-packages/django/template/backends/django.py, line 84, in reraise
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.7.9
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python37.zip',
'/app/.heroku/python/lib/python3.7',
'/app/.heroku/python/lib/python3.7/lib-dynload',
'/app/.heroku/python/lib/python3.7/site-packages']
Server time: Sun, 31 Jan 2021 11:04:58 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /app/templates/main/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templates/main/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/auth/templates/main/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/base/templates/main/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/dashboard/templates/main/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/inventory/templates/main/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/magic/templates/main/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django_filters/templates/main/index.html (Source does not exist)