将Django部署到Heroku时出现服务器错误500

时间:2019-07-23 12:25:04

标签: python django heroku deployment

将django应用程序部署到heroku时出现服务器错误500。 我已经解决了2天,但是不知道要解决什么问题。 我认为djangorestframework会导致此问题,因为它的favicon.ico导致“ GET /favicon.ico HTTP / 1.1” 404 77”,但不知道。

有人发现问题吗? 谢谢您的提前支持!

2019-07-23T12:03:44.622777+00:00 app[api]: Release v23 created by user atnihs-do-21@hotmail.co.jp
2019-07-23T12:03:51.865737+00:00 heroku[web.1]: Starting process with command `gunicorn alumate.wsgi --log-file -`
2019-07-23T12:03:55.314454+00:00 heroku[web.1]: State changed from starting to up
2019-07-23T12:03:55.130912+00:00 app[web.1]: [2019-07-23 12:03:55 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-07-23T12:03:55.132168+00:00 app[web.1]: [2019-07-23 12:03:55 +0000] [4] [INFO] Listening at: http://0.0.0.0:20191 (4)
2019-07-23T12:03:55.132311+00:00 app[web.1]: [2019-07-23 12:03:55 +0000] [4] [INFO] Using worker: sync
2019-07-23T12:03:55.138103+00:00 app[web.1]: [2019-07-23 12:03:55 +0000] [10] [INFO] Booting worker with pid: 10
2019-07-23T12:03:55.150027+00:00 app[web.1]: [2019-07-23 12:03:55 +0000] [11] [INFO] Booting worker with pid: 11
2019-07-23T12:03:55.000000+00:00 app[api]: Build succeeded
2019-07-23T12:04:30.649490+00:00 heroku[router]: at=info method=GET path="/" host=alumate.herokuapp.com request_id=0f1e339a-08fc-4b93-9c1b-1db28b675f76 fwd="210.150.77.215" dyno=web.1 connect=1ms service=835ms status=500 bytes=234 protocol=https
2019-07-23T12:04:30.649933+00:00 app[web.1]: 10.99.197.226 - - [23/Jul/2019:12:04:30 +0000] "GET / HTTP/1.1" 500 27 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
2019-07-23T12:04:31.116073+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=alumate.herokuapp.com request_id=381749d5-0137-4017-bd1b-8bb8cb6feef1 fwd="210.150.77.215" dyno=web.1 connect=0ms service=186ms status=404 bytes=258 protocol=https
2019-07-23T12:04:31.116099+00:00 app[web.1]: 10.99.197.226 - - [23/Jul/2019:12:04:31 +0000] "GET /favicon.ico HTTP/1.1" 404 77 "https://alumate.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"

Settings.py在这里

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = 'XXXXXXXXXXXXXXXX'

DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'rest_framework',
    'widget_tweaks',
    'boards',
    'accounts',
    'auths',
    'my_universities',
    'my_profiles',
    'universities',
    'charts',
    'storages',
]

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

ROOT_URLCONF = 'alumate.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 = 'alumate.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'


STATIC_URL = '/static/'                                             
STATICFILES_DIRS = [                                                
        os.path.join(BASE_DIR, 'static'),
    ]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 


MEDIA_URL = '/media/'                                                
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')   


DEBUG = False

try:
    from .local_settings import *
except ImportError:
    pass

    if not DEBUG:
        import django_heroku
        django_heroku.settings(locals())

我删除了静态文件夹中的图像文件,然后运行python manage.py collectstatic

1 个答案:

答案 0 :(得分:0)

要参考其他有类似问题的人,请将下面的code粘贴到settings.py的底部,并在部署后运行heroku logs --tail --all [your app name]

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