HTML templates aren’t rendering in production. (Heroku)

My HTML templates are not rendering in production, it throws a server error 500, but works locally with debug false

Please reply if you can help me.

settings.py

import django_heroku
from pathlib import Path
import os


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# 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 = ''

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

ALLOWED_HOSTS = ['.herokuapp.com', '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',

    # Custom Apps
    'authSystem',
    'posts',
    
]

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware',

    '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 = 'src.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 = 'src.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 = 'Asia/Kolkata'

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_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATIC_URL = '/static/'

MEDIA_URL = '/images/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images')

# STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


# SMTP CONFIG
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# Activate Django-Heroku.
django_heroku.settings(locals())

logs from heroku

2021-08-28T13:40:24.156453+00:00 heroku[web.1]: Restarting
2021-08-28T13:40:24.167131+00:00 heroku[web.1]: State changed from up to starting
2021-08-28T13:40:24.843937+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-08-28T13:40:25.088647+00:00 app[web.1]: [2021-08-28 19:10:25 +0530] [7] [INFO] Worker exiting (pid: 7)
2021-08-28T13:40:25.088759+00:00 app[web.1]: [2021-08-28 13:40:25 +0000] [4] [INFO] Handling signal: term
2021-08-28T13:40:25.089012+00:00 app[web.1]: [2021-08-28 19:10:25 +0530] [8] [INFO] Worker exiting (pid: 8)
2021-08-28T13:40:25.289354+00:00 app[web.1]: [2021-08-28 13:40:25 +0000] [4] [INFO] Shutting down: Master
2021-08-28T13:40:25.362027+00:00 heroku[web.1]: Process exited with status 0
2021-08-28T13:40:27.473764+00:00 heroku[web.1]: Starting process with command `gunicorn src.wsgi`
2021-08-28T13:40:29.194416+00:00 app[web.1]: [2021-08-28 13:40:29 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-08-28T13:40:29.195878+00:00 app[web.1]: [2021-08-28 13:40:29 +0000] [4] [INFO] Listening at: http://0.0.0.0:47072 (4)
2021-08-28T13:40:29.195928+00:00 app[web.1]: [2021-08-28 13:40:29 +0000] [4] [INFO] Using worker: sync
2021-08-28T13:40:29.198896+00:00 app[web.1]: [2021-08-28 13:40:29 +0000] [7] [INFO] Booting worker with pid: 7
2021-08-28T13:40:29.254827+00:00 app[web.1]: [2021-08-28 13:40:29 +0000] [8] [INFO] Booting worker with pid: 8
2021-08-28T13:40:29.601847+00:00 heroku[web.1]: State changed from starting to up
2021-08-28T13:40:34.000000+00:00 app[api]: Build succeeded
2021-08-28T13:43:20.653546+00:00 app[api]: Starting process with command `python manage.py migrate` by user {{mygmail}}@gmail.com
2021-08-28T13:43:24.305148+00:00 heroku[run.6547]: Awaiting client
2021-08-28T13:43:24.320880+00:00 heroku[run.6547]: Starting process with command `python manage.py migrate`
2021-08-28T13:43:24.429189+00:00 heroku[run.6547]: State changed from starting to up
2021-08-28T13:43:28.777418+00:00 heroku[run.6547]: Process exited with status 0
2021-08-28T13:43:28.846337+00:00 heroku[run.6547]: State changed from up to complete
2021-08-28T13:43:44.800257+00:00 heroku[router]: at=info method=GET path="/auth/login/" host={{name}}.herokuapp.com request_id=03c48371-6c92-4444-8079-a14f4b3208b7 fwd="49.205.247.80" dyno=web.1 connect=0ms service=80ms status=500 bytes=403 protocol=https
2021-08-28T13:43:44.800711+00:00 app[web.1]: 10.1.44.176 - - [28/Aug/2021:19:13:44 +0530] "GET /auth/login/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:43:45.598643+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host={{name}}.herokuapp.com request_id=f292af41-2660-429d-addd-b93a19f93afa fwd="49.205.247.80" dyno=web.1 connect=0ms service=15ms status=404 bytes=411 protocol=https
2021-08-28T13:43:45.598994+00:00 app[web.1]: 10.1.44.176 - - [28/Aug/2021:19:13:45 +0530] "GET /favicon.ico HTTP/1.1" 404 179 "https://{{name}}.herokuapp.com/auth/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:44:07.000000+00:00 app[api]: Build started by user {{mygmail}}@gmail.com
2021-08-28T13:44:55.842703+00:00 app[api]: Release v29 created by user {{mygmail}}@gmail.com
2021-08-28T13:44:55.842703+00:00 app[api]: Deploy ecbebd89 by user {{mygmail}}@gmail.com
2021-08-28T13:44:56.206235+00:00 heroku[web.1]: Restarting
2021-08-28T13:44:56.228254+00:00 heroku[web.1]: State changed from up to starting
2021-08-28T13:44:56.866413+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-08-28T13:44:57.017886+00:00 app[web.1]: [2021-08-28 19:14:57 +0530] [8] [INFO] Worker exiting (pid: 8)
2021-08-28T13:44:57.018020+00:00 app[web.1]: [2021-08-28 19:14:57 +0530] [7] [INFO] Worker exiting (pid: 7)
2021-08-28T13:44:57.022265+00:00 app[web.1]: [2021-08-28 13:44:57 +0000] [4] [INFO] Handling signal: term
2021-08-28T13:44:57.026351+00:00 app[web.1]: [2021-08-28 13:44:57 +0000] [4] [WARNING] Worker with pid 8 was terminated due to signal 15
2021-08-28T13:44:57.026694+00:00 app[web.1]: [2021-08-28 13:44:57 +0000] [4] [WARNING] Worker with pid 7 was terminated due to signal 15
2021-08-28T13:44:57.122714+00:00 app[web.1]: [2021-08-28 13:44:57 +0000] [4] [INFO] Shutting down: Master
2021-08-28T13:44:57.218126+00:00 heroku[web.1]: Process exited with status 0
2021-08-28T13:45:00.386904+00:00 heroku[web.1]: Starting process with command `gunicorn src.wsgi`
2021-08-28T13:45:02.680215+00:00 app[web.1]: [2021-08-28 13:45:02 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-08-28T13:45:02.680611+00:00 app[web.1]: [2021-08-28 13:45:02 +0000] [4] [INFO] Listening at: http://0.0.0.0:40281 (4)
2021-08-28T13:45:02.680654+00:00 app[web.1]: [2021-08-28 13:45:02 +0000] [4] [INFO] Using worker: sync
2021-08-28T13:45:02.683912+00:00 app[web.1]: [2021-08-28 13:45:02 +0000] [7] [INFO] Booting worker with pid: 7
2021-08-28T13:45:02.726880+00:00 app[web.1]: [2021-08-28 13:45:02 +0000] [8] [INFO] Booting worker with pid: 8
2021-08-28T13:45:03.164993+00:00 heroku[web.1]: State changed from starting to up
2021-08-28T13:45:07.000000+00:00 app[api]: Build succeeded
2021-08-28T13:46:05.000000+00:00 app[api]: Build started by user {{mygmail}}@gmail.com
2021-08-28T13:46:34.393998+00:00 app[api]: Release v30 created by user {{mygmail}}@gmail.com
2021-08-28T13:46:34.393998+00:00 app[api]: Deploy ecbebd89 by user {{mygmail}}@gmail.com
2021-08-28T13:46:34.663251+00:00 heroku[web.1]: Restarting
2021-08-28T13:46:34.703722+00:00 heroku[web.1]: State changed from up to starting
2021-08-28T13:46:35.454950+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-08-28T13:46:35.570839+00:00 app[web.1]: [2021-08-28 19:16:35 +0530] [7] [INFO] Worker exiting (pid: 7)
2021-08-28T13:46:35.570846+00:00 app[web.1]: [2021-08-28 19:16:35 +0530] [8] [INFO] Worker exiting (pid: 8)
2021-08-28T13:46:35.570847+00:00 app[web.1]: [2021-08-28 13:46:35 +0000] [4] [INFO] Handling signal: term
2021-08-28T13:46:35.773637+00:00 app[web.1]: [2021-08-28 13:46:35 +0000] [4] [INFO] Shutting down: Master
2021-08-28T13:46:35.870230+00:00 heroku[web.1]: Process exited with status 0
2021-08-28T13:46:38.255764+00:00 heroku[web.1]: Starting process with command `gunicorn src.wsgi`
2021-08-28T13:46:40.063157+00:00 app[web.1]: [2021-08-28 13:46:40 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-08-28T13:46:40.064533+00:00 app[web.1]: [2021-08-28 13:46:40 +0000] [4] [INFO] Listening at: http://0.0.0.0:25190 (4)
2021-08-28T13:46:40.064571+00:00 app[web.1]: [2021-08-28 13:46:40 +0000] [4] [INFO] Using worker: sync
2021-08-28T13:46:40.067395+00:00 app[web.1]: [2021-08-28 13:46:40 +0000] [7] [INFO] Booting worker with pid: 7
2021-08-28T13:46:40.152070+00:00 app[web.1]: [2021-08-28 13:46:40 +0000] [8] [INFO] Booting worker with pid: 8
2021-08-28T13:46:40.463360+00:00 heroku[web.1]: State changed from starting to up
2021-08-28T13:46:45.000000+00:00 app[api]: Build succeeded
2021-08-28T13:46:55.837912+00:00 app[web.1]: 10.1.42.161 - - [28/Aug/2021:19:16:55 +0530] "GET / HTTP/1.1" 302 0 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:46:55.839557+00:00 heroku[router]: at=info method=GET path="/" host={{name}}.herokuapp.com request_id=dce48a07-1c53-4e25-b07c-4474c15b38dc fwd="49.205.247.80" dyno=web.1 connect=0ms service=31ms status=302 bytes=279 protocol=https
2021-08-28T13:46:56.163193+00:00 app[web.1]: 10.1.42.161 - - [28/Aug/2021:19:16:56 +0530] "GET /auth/login/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:46:56.164769+00:00 heroku[router]: at=info method=GET path="/auth/login/" host={{name}}.herokuapp.com request_id=2f81ef2a-88df-47f0-91e7-b41ef58b3b86 fwd="49.205.247.80" dyno=web.1 connect=0ms service=96ms status=500 bytes=403 protocol=https
2021-08-28T13:46:56.995335+00:00 app[web.1]: 10.1.42.161 - - [28/Aug/2021:19:16:56 +0530] "GET /favicon.ico HTTP/1.1" 404 179 "https://{{name}}.herokuapp.com/auth/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:46:56.996947+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host={{name}}.herokuapp.com request_id=2820dc0a-5330-47fe-91f9-4df589c3f848 fwd="49.205.247.80" dyno=web.1 connect=0ms service=16ms status=404 bytes=411 protocol=https
2021-08-28T13:50:35.931784+00:00 app[web.1]: 10.1.27.43 - - [28/Aug/2021:19:20:35 +0530] "GET /auth/login/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:50:35.935383+00:00 heroku[router]: at=info method=GET path="/auth/login/" host={{name}}.herokuapp.com request_id=c344e0e9-c111-47b7-b764-85068dbb4368 fwd="49.205.247.80" dyno=web.1 connect=0ms service=16ms status=500 bytes=403 protocol=https
2021-08-28T13:50:36.562523+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host={{name}}.herokuapp.com request_id=2dba5d9d-05a9-433e-bae0-d6200008e403 fwd="49.205.247.80" dyno=web.1 connect=0ms service=2ms status=404 bytes=411 protocol=https
2021-08-28T13:50:36.562615+00:00 app[web.1]: 10.1.27.43 - - [28/Aug/2021:19:20:36 +0530] "GET /favicon.ico HTTP/1.1" 404 179 "https://{{name}}.herokuapp.com/auth/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:50:47.517989+00:00 heroku[router]: at=info method=GET path="/auth/login/" host={{name}}.herokuapp.com request_id=2be1956e-2538-4faf-8dbb-15ebdf1a82ec fwd="49.205.247.80" dyno=web.1 connect=0ms service=12ms status=500 bytes=403 protocol=https
2021-08-28T13:50:47.518110+00:00 app[web.1]: 10.1.27.43 - - [28/Aug/2021:19:20:47 +0530] "GET /auth/login/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:50:48.327851+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host={{name}}.herokuapp.com request_id=860aaf25-18d8-4ed4-b1f7-25439a439eb7 fwd="49.205.247.80" dyno=web.1 connect=0ms service=2ms status=404 bytes=411 protocol=https
2021-08-28T13:50:48.327970+00:00 app[web.1]: 10.1.27.43 - - [28/Aug/2021:19:20:48 +0530] "GET /favicon.ico HTTP/1.1" 404 179 "https://{{name}}.herokuapp.com/auth/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:52:13.506632+00:00 app[web.1]: 10.1.39.164 - - [28/Aug/2021:19:22:13 +0530] "GET /auth/login/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:52:13.507480+00:00 heroku[router]: at=info method=GET path="/auth/login/" host={{name}}.herokuapp.com request_id=e90fb1e2-ec95-4aa3-b907-77af8f684c78 fwd="49.205.247.80" dyno=web.1 connect=0ms service=11ms status=500 bytes=403 protocol=https
2021-08-28T13:52:14.230251+00:00 app[web.1]: 10.1.39.164 - - [28/Aug/2021:19:22:14 +0530] "GET /favicon.ico HTTP/1.1" 404 179 "https://{{name}}.herokuapp.com/auth/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:52:14.230928+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host={{name}}.herokuapp.com request_id=c3951a46-05ca-491c-9b21-7a40e4d8517a fwd="49.205.247.80" dyno=web.1 connect=0ms service=2ms status=404 bytes=411 protocol=https
2021-08-28T13:52:14.938169+00:00 app[web.1]: 10.1.39.164 - - [28/Aug/2021:19:22:14 +0530] "GET /auth/login/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:52:14.938871+00:00 heroku[router]: at=info method=GET path="/auth/login/" host={{name}}.herokuapp.com request_id=10d0e642-f77a-4ae0-a747-dab970a57316 fwd="49.205.247.80" dyno=web.1 connect=0ms service=11ms status=500 bytes=403 protocol=https
2021-08-28T13:52:15.495790+00:00 app[web.1]: 10.1.39.164 - - [28/Aug/2021:19:22:15 +0530] "GET /favicon.ico HTTP/1.1" 404 179 "https://{{name}}.herokuapp.com/auth/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:52:15.496576+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host={{name}}.herokuapp.com request_id=ba799260-3c44-430e-bb7b-61c0a7abbc39 fwd="49.205.247.80" dyno=web.1 connect=0ms service=2ms status=404 bytes=411 protocol=https
2021-08-28T13:52:15.723176+00:00 app[web.1]: 10.1.39.164 - - [28/Aug/2021:19:22:15 +0530] "GET /auth/login/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
2021-08-28T13:52:15.723934+00:00 heroku[router]: at=info method=GET path="/auth/login/" host={{name}}.herokuapp.com request_id=e764ff7e-a5e4-424f-b20d-5bf2a0a92ec9 fwd="49.205.247.80" dyno=web.1 connect=0ms service=10ms status=500 bytes=403 protocol=https

I’ve tried updating my requirements.txt and also ran Heroku run python manage.py migrate and few other things I can’t remember, but no luck :frowning:

Please if someone can help me, Reply

I would try setting the ADMINS setting and see if the emails come through to determine what the error is.

If that’s not possible, then I’d enable DEBUG=True for a brief amount of time on the heroku app. If you can’t enable production there because it’d expose info to users you don’t want it to, then I’d create a second heroku app, recreate the problem, enable DEBUG, then work from the actual error.