DjangoでWebアプリを制作しています。
https://qiita.com/frosty/items/66f5dff8fc723387108c
こちらのサイトを参考にデプロイしています。
herokuでは以下のコマンドは通りました。
termminal
1git push heroku master 2heroku ps:scale web=1 3heroku run python manage.py migrate 4heroku run python manage.py createsuperuser
しかし、heroku openを実行するとサイトは表示されますが全ページServer Error (500)になります。
コードは以下のような状態です。
settings
1from pathlib import Path 2import os 3import dj_database_url 4DEBUG = False 5 6 7# Build paths inside the project like this: BASE_DIR / 'subdir'. 8BASE_DIR = Path(__file__).resolve().parent.parent 9 10 11# Quick-start development settings - unsuitable for production 12# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 13 14# SECURITY WARNING: keep the secret key used in production secret! 15 16 17# SECURITY WARNING: don't run with debug turned on in production! 18 19 20ALLOWED_HOSTS = ['127.0.0.1','kairans.herokuapp.com'] 21 22 23# Application definition 24 25INSTALLED_APPS = [ 26 'django.contrib.admin', 27 'django.contrib.auth', 28 'django.contrib.contenttypes', 29 'django.contrib.sessions', 30 'django.contrib.messages', 31 'django.contrib.staticfiles', 32 'cloudinary_storage', 33 'cloudinary', 34 'django_cleanup', 35 'kairans_app.apps.KairansAppConfig', 36 'django.contrib.sites', 37 'allauth', 38 'allauth.account', 39 'allauth.socialaccount', 40] 41 42MIDDLEWARE = [ 43 'django.middleware.security.SecurityMiddleware', 44 'whitenoise.middleware.WhiteNoiseMiddleware', 45 'django.contrib.sessions.middleware.SessionMiddleware', 46 'django.middleware.common.CommonMiddleware', 47 'django.middleware.csrf.CsrfViewMiddleware', 48 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 'django.contrib.messages.middleware.MessageMiddleware', 50 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 52] 53 54ROOT_URLCONF = 'config.urls' 55 56TEMPLATES = [ 57 { 58 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 'DIRS': [Path(BASE_DIR, 'templates')], 60 'APP_DIRS': True, 61 'OPTIONS': { 62 'context_processors': [ 63 'django.template.context_processors.debug', 64 'django.template.context_processors.request', 65 'django.contrib.auth.context_processors.auth', 66 'django.contrib.messages.context_processors.messages', 67 ], 68 }, 69 }, 70] 71 72WSGI_APPLICATION = 'config.wsgi.application' 73 74 75# Database 76# https://docs.djangoproject.com/en/3.1/ref/settings/#databases 77 78DATABASES = { 79 'default': { 80 'ENGINE': 'django.db.backends.postgresql_psycopg2', 81 'NAME': 'name', 82 'USER': 'user', 83 'PASSWORD': '', 84 'HOST': 'host', 85 'PORT': '', 86 } 87} 88 89 90# Password validation 91# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 92 93AUTH_PASSWORD_VALIDATORS = [ 94 { 95 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 96 }, 97 { 98 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 99 }, 100 { 101 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 102 }, 103 { 104 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 105 }, 106] 107 108 109# Internationalization 110# https://docs.djangoproject.com/en/3.1/topics/i18n/ 111 112LANGUAGE_CODE = 'ja' 113 114TIME_ZONE = 'Asia/Tokyo' 115 116USE_I18N = True 117 118USE_L10N = True 119 120USE_TZ = True 121 122 123# Static files (CSS, JavaScript, Images) 124# https://docs.djangoproject.com/en/3.1/howto/static-files/ 125 126#CSS 127STATIC_URL = '/static/' 128STATICFILES_DIRS = [ 129 os.path.join(BASE_DIR, 'static'), 130] 131 132STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 133 134AUTH_USER_MODEL = 'kairans_app.User' 135 136 137LOGIN_REDIRECT_URL = 'index' 138ACCOUNT_LOGOUT_REDIRECT_URL = '/accounts/login/' 139 140 141CLOUDINARY_STORAGE = { 142 'CLOUD_NAME': '****', 143 'API_KEY': '****', 144 'API_SECRET': '****' 145} 146 147MEDIA_URL = '/media/' 148DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage' 149 150 151EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 152#EMAIL_HOST = 'smtp.gmail.com' 153EMAIL_HOST = 'smtp.sendgrid.net' 154#EMAIL_HOST_USER = '****' 155EMAIL_HOST_USER = 'apikey' 156#EMAIL_HOST_PASSWORD = '****' 157EMAIL_HOST_PASSWORD = '****' 158EMAIL_PORT = 587 159EMAIL_USE_TLS = True 160DEFAULT_FROM_EMAIL = '****' 161 162AUTHENTICATION_BACKENDS = ( 163 # Needed to login by username in Django admin, regardless of `allauth` 164 "django.contrib.auth.backends.ModelBackend", 165 166 # `allauth` specific authentication methods, such as login by e-mail 167 "allauth.account.auth_backends.AuthenticationBackend", 168) 169 170SITE_ID = 1 171 172ACCOUNT_EMAIL_REQUIRED = True 173ACCOUNT_USERNAME_REQUIRED = True 174ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = True 175ACCOUNT_SESSION_REMEMBER = True 176ACCOUNT_AUTHENTICATION_METHOD = 'email' 177ACCOUNT_UNIQUE_EMAIL = True 178ACCOUNT_EMAIL_VERIFICATION = 'mandatory' 179 180 181try: 182 from .local_settings import * 183except ImportError: 184 pass 185 186if not DEBUG: 187 SECRET_KEY = os.environ['SECRET_KEY'] 188 import django_heroku 189 django_heroku.settings(locals()) 190 191db_from_env = dj_database_url.config(conn_max_age=600, ssl_require=True) 192DATABASES['default'].update(db_from_env) 193
herokuのログは以下のようになっていましたが、何が原因なのかわかりませんでした。
terminal
12021-05-23T01:17:50.373817+00:00 app[web.1]: 10.45.25.242 - - [23/May/2021:10:17:50 +0900] "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" 22021-05-23T01:17:50.378278+00:00 heroku[router]: at=info method=GET path="/" host=kairans.herokuapp.com request_id=04db8619-6827-426a-9fd7-2e12c5cc6be5 fwd="49.251.90.26" dyno=web.1 connect=1ms service=1101ms status=500 bytes=403 protocol=https 32021-05-23T01:17:51.164517+00:00 app[web.1]: 10.45.25.242 - - [23/May/2021:10:17:51 +0900] "GET /favicon.ico HTTP/1.1" 500 145 "https://kairans.herokuapp.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" 42021-05-23T01:17:51.169246+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=kairans.herokuapp.com request_id=7dde5076-4ce5-418d-a8b0-f4d0664a8204 fwd="49.251.90.26" dyno=web.1 connect=1ms service=113ms status=500 bytes=389 protocol=https
faviconの拡張子を.pmgから.icoに変更したりしましたが変わりませんでした。
よろしくお願いします。
あなたの回答
tips
プレビュー