部署后 Django heroku 内部服务器错误

Django heroku internal server error after deploying

我已经将我的 django 应用程序部署到 heroku,我在网站上得到 Internal Server Error

settings.py :

'ALLOWED_HOSTS = ['http://127.0.0.1:8000/','https://stripetestdjango.herokuapp.com/', 'localhost']

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',

    'whitenoise.middleware.WhiteNoiseMiddleware',

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


MEDIA_URL = '/images/'


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

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


MEDIA_ROOT = BASE_DIR / 'static/images'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

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



if os.getcwd() == '/app':
    DEBUG = False

heroku 日志显示如下:

我有 .env 文件。如何将其推送到服务器以及我正在使用 heroku 进行部署。我想错误是找不到我的 .env 文件。

如有需要,请随时询问更多详情。

您应该永远不要推送包含敏感数据(即SECRET_KEY_STRIPE)的.env文件,而是使用Heroku Config Vars.

您可以使用 Python os 获取环境变量,而在您的本地开发环境中,最好将 .env 保留为 [=] 所需的值24=].

def get_mysecret():
  return os.environ.get("MY_SECRET", "")

查看屏幕截图(如果您愿意,可以使用命令行创建配置变量):