Django_heroku.settings(locals()) KeyError: 'MIDDLEWARE' and 'MIDDLEWARE_CLASSES'

settings.py

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ALLOWED_HOSTS = ['my-app.herokuapp.com', '127.0.0.1:8000', 'localhost']

django_heroku.settings(locals())

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'build/assets')
]

error (2 exceptions)

remote: Traceback (most recent call last):
remote:   File "/app/.heroku/python/lib/python3.9/site-packages/django_heroku/core.py", line 97, in settings
remote:     config['MIDDLEWARE_CLASSES'] = tuple(['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE_CLASSES']))
remote: KeyError: 'MIDDLEWARE_CLASSES'

remote:     django_heroku.settings(locals())
remote:   File "/app/.heroku/python/lib/python3.9/site-packages/django_heroku/core.py", line 99, in settings
remote:     config['MIDDLEWARE'] = tuple(['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE']))
remote: KeyError: 'MIDDLEWARE'

I am trying to deploy my web app but I am getting this error everytime, cannot find a solution anywhere... nothing wrong with the Procfile, requirements.txt and runtime.txt, any help is appreciated!

Nevermind I fixed it, in my file django_heroku.settings(locals()) was above the middleware list so that was causing the errors... now I have a problem where app.settings is not found, guess another question is inevitable.

Back to Top