Server 500 error only when deploying to Heroku with DEBUG=False

Here is the broken site & error page:

Abstract Spacecraft

The site works perfectly as it does locally when DEBUG = True. I have an ON_HEROKU=1 config variable set through the Heroku dashboard for the app, which causes the branch in to set DEBUG = False.

I tried setting it back to DEBUG = True, and everything else the same, and the site then works.

Here is my

Django settings for abstract_spacecraft project.

Generated by 'django-admin startproject' using Django 3.1.5.

For more information on this file, see

For the full list of settings and their values, see

from pathlib import Path
import os
import django_heroku
import dj_database_url

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
SITE_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))

# Quick-start development settings - unsuitable for production
# See

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'TODO: use secret key in deployment')

# SECURITY WARNING: don't run with debug turned on in production!
if os.environ.get('ON_HEROKU', '0') == '0':
    DEBUG = True
    DEBUG = False

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


# Application definition



ROOT_URLCONF = 'abstract_spacecraft.urls'

TEMPLATES_PATH = os.path.join(SETTINGS_PATH, 'templates')

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
                 os.path.join(TEMPLATES_PATH, 'abstract_spacecraft'),
                 os.path.join(TEMPLATES_PATH, 'accounts'),
                 os.path.join(TEMPLATES_PATH, 'cd_editor'),
                 os.path.join(TEMPLATES_PATH, 'database')],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug': True,
            'context_processors': [

WSGI_APPLICATION = 'abstract_spacecraft.wsgi.application'

# Database

# TODO: try out PostgreSQL in production, i.e. change True to the commented out code;
if os.environ.get('ON_HEROKU', '0') == '0':
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': BASE_DIR / 'db.sqlite3',
        # TODO: what does this max_age setting do?
        'default' : dj_database_url.config(conn_max_age=600)

# Password validation

        '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



USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
  os.path.join(SITE_ROOT, 'static/'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

def neo4j_url():
    url = os.environ.get('NEO4J_SCHEMA', 'bolt') + "://"
    url += os.environ.get('NEO4J_USERNAME', 'neo4j') + ":"
    url += os.environ.get('NEO4J_PASSWORD', 'fusion123') + "@"
    url += os.environ.get('NEO4J_HOST', 'localhost') + ":"
    url += os.environ.get('NEO4J_PORT', '7687')
    return url


NEOMODEL_ENCRYPTED_CONNECTION = False  # TODO: how do we switch this on without error?

from neomodel import config   # BUGFIX: had to do it this way
config.MAX_POOL_SIZE = 50  # TODO: what does this affect?


# TODO: Enable Click-jacking protection
X_FRAME_OPTIONS = 'ALLOW'   # ie set this to "DENY"



    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
    'loggers': {
        'django': {
            'handlers': ['console'],
             'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),

# Activate Django-Heroku.

The last part about LOGGING didn’t seem to do anything because I don’t see any extra logs or messages to the console anywhere on Heroku.

Have you tried testing locally with DEBUG = False?


@fabtjar I get the following error message, which is having to do with static files. However, I tried changing the


line to


and it’s the same error, an error that gets thrown while reading a template of mine.

File "C:\Python39\Lib\site-packages\django\contrib\staticfiles\", line 147, in url
return self._url(self.stored_name, name, force)
File "C:\Python39\Lib\site-packages\django\contrib\staticfiles\", line 126, in _url
hashed_name = hashed_name_func(*args)
File "C:\Python39\Lib\site-packages\django\contrib\staticfiles\", line 417, in stored_name
raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)

builtins.ValueError: Missing staticfiles manifest entry for 'bootstrap\css\bootstrap.min.css'

During handling of the above exception, another exception occurred:

File "C:\Python39\Lib\", line 930, in _bootstrap
File "C:\Python39\Lib\", line 973, in _bootstrap_inner
File "C:\Python39\Lib\", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Python39\Lib\", line 683, in process_request_thread
self.finish_request(request, client_address)
File "C:\Python39\Lib\", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python39\Lib\", line 747, in __init__
File "C:\Python39\Lib\wsgiref\", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python39\Lib\site-packages\whitenoise\", line 59, in __call__
response = self.get_response(request)
File "C:\Python39\Lib\site-packages\whitenoise\", line 59, in __call__
response = self.get_response(request)
![](C:\Program Files (x86)\Wing Pro 7.2/resources/icons/bookmarks_excpanel.png) File "C:\Users\FruitfulApproach\Desktop\abstract_spacecraft\database-of-proofs-engine\accounts\", line 19, in sign_up
return render(request, 'sign_up.html', {'form': form})
![](C:\Program Files (x86)\Wing Pro 7.2/resources/icons/bookmarks_excpanel.png) File "c:\users\fruitfulapproach\desktop\abstract_spacecraft\database-of-proofs-engine\templates\accounts\sign_up.html", line (257, 303), in <django.templatetags.static.StaticNode object at 0x0000011CBF8CF370>
b'{% static "bootstrap\\css\\bootstrap.min.css" %}'


I also tried the solution here:

SO answer

and 3 other answers on StackOverflow, but same issues - either Server 500 (on heroku) or the above error (local).

I did run python collectstatic before running locally, and deploying to Heroku does this for you.

Does it error when you collect static locally? Can you show the sign up html page where you use the static CSS file?

1 Like

@fabtjar yes, still errors when collecting static locally. I get:

Not Found

The requested resource was not found on this server.
When I direct browser to domain/sign-in

The full code is here:
Github Repo

I mean the source for the html page. Are you sure the path to the CSS is correct?

1 Like

@fabtjar if it’s correct in development mode, it ought to be correct in production mode! :slight_smile:

I was asking because the error message shows ‘bootstrap\\css\\bootstrap.min.css’. I was just thinking are you using backslash because when you’re on Windows? I’m guessing Heroku’s server would be Linux.

1 Like

@fabtjar this error is taken from local though (Windows). I’ll try editing the template…

Thank you for solving this! Windows (local) running likes this as well, probably something to do with whatever server Django uses for serving files, i.e. that it needs forward slashes. Will have to update my BootstrapStudio export script (how I made the Bootstrap5 templates).

1 Like

I have the same problem. Also on cPanel deploy. This comment helped med get closer to the answer. Stil investigating.

In case you’re wondering why static files and images don’t work when Debug = False:

I made images/static files be served by NGINX by configuring the config file like so:


location: project root directory/nginx

upstream django {
    server django_gunicorn:8000; #I want the nginx server to proxy for this server and port

server {

listen 80; #proxy listens on port 80
client_max_body_size 30M; # max upload file size

   location / { #if it's not a static file, the request gets passed back to port 8000

       proxy_pass http://django; #"django" is inferred from what the upstream name was defined as

   location /home/APROOT/app/jb_quality_prj/static/ {
       alias /static; # make nginx serve the static files

   location /home/APPROOT/app/jb_quality_prj/media/ {
       alias /media; # make nginx serve the media files

location: project root directory/nginx

FROM nginx:1.19.0-alpine

COPY ./default.conf /etc/nginx/conf.d/default.conf