前提・実現したいこと
Djangoにて作成したアプリをherokuへデプロイを試みていますが、server error(500)
が表示されるだけとなっています。これを正しく表示させたいです。
python: 3.6.8
django: 2.1.5
発生している問題・エラーメッセージ
- heroku logs
2019-02-26T07:30:19.083159+00:00 heroku[web.1]: Process exited with status 0 2019-02-26T07:30:25.950098+00:00 heroku[web.1]: Starting process with command `gunicorn project5.wsgi --log-file -` 2019-02-26T07:30:28.851068+00:00 heroku[web.1]: State changed from starting to up 2019-02-26T07:30:28.680601+00:00 app[web.1]: [2019-02-26 07:30:28 +0000] [4] [INFO] Starting gunicorn 19.9.0 2019-02-26T07:30:28.681522+00:00 app[web.1]: [2019-02-26 07:30:28 +0000] [4] [INFO] Listening at: http://0.0.0.0:57218 (4) 2019-02-26T07:30:28.681659+00:00 app[web.1]: [2019-02-26 07:30:28 +0000] [4] [INFO] Using worker: sync 2019-02-26T07:30:28.691509+00:00 app[web.1]: [2019-02-26 07:30:28 +0000] [10] [INFO] Booting worker with pid: 10 2019-02-26T07:30:28.730851+00:00 app[web.1]: [2019-02-26 07:30:28 +0000] [11] [INFO] Booting worker with pid: 11 2019-02-26T07:30:32.050252+00:00 heroku[router]: at=info method=GET path="/" host=shunka-blog.herokuapp.com request_id=c9243db5-e8d7-40f8-b57c-281532c2606a fwd="219.122.164.206" dyno=web.1 connect=1ms service=2878ms status=500 bytes=234 protocol=https 2019-02-26T07:30:32.050265+00:00 app[web.1]: 10.43.192.217 - - [26/Feb/2019:16:30:32 +0900] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"
- ブラウザ上
Server Error (500)
該当のソースコード
settings.py
python
1import os 2import dj_database_url 3import django_heroku 4 5BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 6 7DEBUG = False 8 9SECRET_KEY = *** 10 11ALLOWED_HOSTS = ['*'] 12 13 14# Application definition 15 16INSTALLED_APPS = [ 17 'blog5.apps.Blog5Config', 18 'django.contrib.admin', 19 'django.contrib.auth', 20 'django.contrib.contenttypes', 21 'django.contrib.sessions', 22 'django.contrib.messages', 23 'django.contrib.staticfiles', 24 'django.contrib.humanize', 25 'markdownx', 26 'widget_tweaks', 27] 28 29MIDDLEWARE = [ 30 'django.middleware.security.SecurityMiddleware', 31 'whitenoise.middleware.WhiteNoiseMiddleware', 32 'django.contrib.sessions.middleware.SessionMiddleware', 33 'django.middleware.common.CommonMiddleware', 34 'django.middleware.csrf.CsrfViewMiddleware', 35 'django.contrib.auth.middleware.AuthenticationMiddleware', 36 'django.contrib.messages.middleware.MessageMiddleware', 37 'django.middleware.clickjacking.XFrameOptionsMiddleware', 38] 39 40STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 41 42ROOT_URLCONF = 'project5.urls' 43 44TEMPLATES = [ 45 { 46 'BACKEND': 'django.template.backends.django.DjangoTemplates', 47 'DIRS': [], 48 'APP_DIRS': True, 49 'OPTIONS': { 50 'context_processors': [ 51 'django.template.context_processors.debug', 52 'django.template.context_processors.request', 53 'django.contrib.auth.context_processors.auth', 54 'django.contrib.messages.context_processors.messages', 55 ], 56 }, 57 }, 58] 59 60WSGI_APPLICATION = 'project5.wsgi.application' 61 62DATABASES = { 'default': dj_database_url.config() } 63SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 64 65AUTH_PASSWORD_VALIDATORS = [ 66 { 67 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 68 }, 69 { 70 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 71 }, 72 { 73 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 74 }, 75 { 76 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 77 }, 78] 79 80LANGUAGE_CODE = 'ja' 81 82TIME_ZONE = 'Asia/Tokyo' 83 84USE_I18N = True 85 86USE_L10N = True 87 88USE_TZ = True 89 90STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 91STATIC_URL = '/static/' 92 93# STATICFILES_DIRS = ( 94# os.path.join(BASE_DIR, 'static'), 95# ) 96 97MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 98MEDIA_URL = '/media/' 99 100os.makedirs(STATIC_ROOT, exist_ok=True) 101 102try: 103 from .local_settings import * 104except ImportError: 105 pass 106 107django_heroku.settings(locals()) 108
wsgi.py
import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project5.settings') application = get_wsgi_application()
git push heroku master
(django2) shimizushunyuunoMacBook-Pro:project5 shimizushunyuu$ git push heroku master Enumerating objects: 7, done. Counting objects: 100% (7/7), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 349 bytes | 349.00 KiB/s, done. Total 4 (delta 3), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Python app detected remote: -----> Installing requirements with pip remote: remote: -----> $ python manage.py collectstatic --noinput remote: 222 static files copied to '/tmp/build_81a3b3c79381c655da2c216eda585d9b/staticfiles', 658 post-processed. remote: remote: -----> Discovering process types remote: Procfile declares types -> web remote: remote: -----> Compressing... remote: Done: 101.9M remote: -----> Launching... remote: Released v18 remote: https://shunka-blog.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/shunka-blog.git 50d10c3..2a9623c master -> master
試したこと
デプロイ自体はcollectstatics含め問題無く完了します。試しにDEBUG=Trueにてデプロイして見たところ、問題なく表示されましたので、静的ファイル関連の問題だと思っています。
whitenoiseを導入してもエラーが消えずお手上げ状態です。どなたか解決方法をご教授願えませんでしょうか。
(設定にはhttps://devcenter.heroku.com/articles/django-assetsを参考にしました。)
何卒宜しくお願い致します。
回答2件
あなたの回答
tips
プレビュー