django_heroku.settings(locals()) KeyError: 'MIDDLEWARE' 和 'MIDDLEWARE_CLASSES'

Posted

技术标签:

【中文标题】django_heroku.settings(locals()) KeyError: \'MIDDLEWARE\' 和 \'MIDDLEWARE_CLASSES\'【英文标题】:django_heroku.settings(locals()) KeyError: 'MIDDLEWARE' and 'MIDDLEWARE_CLASSES'django_heroku.settings(locals()) KeyError: 'MIDDLEWARE' 和 'MIDDLEWARE_CLASSES' 【发布时间】:2022-01-17 22:25:33 【问题描述】:

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')
]

错误(2 个例外)

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'

我正在尝试部署我的网络应用程序,但每次都遇到此错误,无法在任何地方找到解决方案... Procfile、requirements.txt 和 runtime.txt 没有任何问题,感谢任何帮助!

【问题讨论】:

运行collect static时会出现吗? 不,我禁用了它。 【参考方案1】:

没关系,我修复了它,在我的文件中 django_heroku.settings(locals()) 是 above 中间件列表,因此导致错误...现在我遇到了 app.settings 所在的问题没找到,猜猜另一个问题是不可避免的。

【讨论】:

以上是关于django_heroku.settings(locals()) KeyError: 'MIDDLEWARE' 和 'MIDDLEWARE_CLASSES'的主要内容,如果未能解决你的问题,请参考以下文章

VMware安装linux无网卡,只有lo网卡

linux本地回环lo有啥用

linux下的so,o,lo,a,la文件有啥区别

[pdo_mysql.lo] Error 1 或者 [php_mysql.lo] Error 1

Lo口是啥意思?Po口是啥意思?

如何百倍加速 Lo-Dash?引入惰性计算