前提・実現したいこと
git push heroku mainしてheroku openするとserver error(500)となってしまします。heroku logsでログを確認すると、djangoのログイン画面でエラーが起きているように思えるのですが、〇〇ERRORのようなメッセージも無く、どのように対処すればよいかが分かりません。
ご教示よろしくお願い致します。
ローカルではエラー無く稼働します。
migrate,createsupruserは実施済みです。
発生している問題・エラーメッセージ
log
2020-11-18T02:38:47.305407+00:00 app[web.1]: 10.69.229.158 - - 18/Nov/2020:11:38:47 +0900] "GET / HTTP/1.1" 302 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69" 2020-11-18T02:38:47.306543+00:00 heroku[router]: at=info method=GET path="/" host=アプリ名.herokuapp.com request_id=0aafd9dd-6185-47a5-93da-2e0a570662c4 fwd="111.239.167.18" dyno=web.1 connect=1ms service=4ms status=302 bytes=266 protocol=https 2020-11-18T02:38:47.578580+00:00 app[web.1]: 10.69.229.158 - -[18/Nov/2020:11:38:47 +0900] "GET /accounts/login/?next=/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69" 2020-11-18T02:38:47.579524+00:00 heroku[router]: at=info method=GET path="/accounts/login/?next=/" host=アプリ名.herokuapp.com request_id=b8947b9b-962f-4503-a833-18bac7c66ea2 fwd="111.239.167.18" dyno=web.1 connect=1ms service=27ms status=500 bytes=380 protocol=https
該当のソースコード
settings
""" Django settings for deploy project. Generated by 'django-admin startproject' using Django 3.0.7. For more information on this file, see https://docs.djangoproject.com/en/3.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.0/ref/settings/ """ import os from django.contrib import admin ###admin画面の表示設定 admin.AdminSite.site_title = 'ログインページ' admin.AdminSite.site_header = '管 理 画 面' admin.AdminSite.index_title = 'メニュー' ###ログイン関連 LOGIN_URL='/accounts/login'#<-- ログインURL LOGIN_REDIRECT_URL='/'#<-- ログイン後トップページにリダイレクト LOGOUT_REDIRECT_URL='/'#<-- ログアウト後トップページにリダイレクト ## osgeo4wはlocal_settings.pyに移動 ## # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '8@x_612*9gnu=f)es2)_y8%h(h_=fjgajn1t644dj#v*oh8hd2' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False ALLOWED_HOSTS = [ "アプリ名" ] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.templatetags.static', 'django.contrib.gis', 'django_cleanup.apps.CleanupConfig', # django-cleanup 'map.apps.MapConfig', 'deploy', 'leaflet', 'six', 'django_filters', 'rest_framework', 'rest_framework_gis', 'markdown', 'PIL', 'PIL.ExifTags', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', # heroku追加 '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 = 'deploy.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 = 'deploy.wsgi.application' # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases """ DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'geodjangodb3', 'USER': 'geo_admin', 'PASSWORD': 'geoadmin', 'HOST': 'localhost', 'PORT':'5432',#heroku } } """ # Password validation # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 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', }, ] # Internationalization # https://docs.djangoproject.com/en/3.0/topics/i18n/ LANGUAGE_CODE = 'ja-JP' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True USE_TZ = True # ログイン後、10時間でタイムアウト SESSION_COOKIE_AGE = 36000 # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')#元はstatic STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)#元はmap/atatic # ↓ heroku追加 STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' # heroku用 try: from .local_settings import * except ImportError: pass if not DEBUG: import django_heroku django_heroku.settings(locals()) import dj_database_url DATABASES['default'] = dj_database_url.config() DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis' GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH') GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')
procfile
web: gunicorn geodj.wsgi --log-file -
requirements.txt
requirements
asgiref==3.2.9 brotlipy==0.7.0 certifi==2020.6.20 cffi==1.14.0 chardet==3.0.4 cryptography==2.9.2 dj-database-url==0.5.0 Django==3.0.7 django-cleanup==5.1.0 django-cors-headers==3.2.1 django-filter==2.3.0 django-heroku==0.3.1 django-leaflet==0.27.1 djangorestframework==3.11.0 djangorestframework-gis==0.15 fastcache==1.1.0 future==0.18.2 glob2==0.7 gunicorn==20.0.4 idna==2.9 importlib-metadata==1.6.1 Markdown==3.2.2 mpmath==1.1.0 olefile==0.46 Pillow==7.2.0 psycopg2==2.8.5 psycopg2-binary==2.8.6 pycparser==2.20 pyOpenSSL==19.1.0 PySocks==1.7.1 pytz==2020.1 requests==2.24.0 six==1.14.0 sqlparse==0.3.1 sympy==1.6.2 urllib3==1.25.9 whitenoise==5.2.0 win-inet-pton==1.1.0 wincertstore==0.2 zipp==3.1.0
wsgi.py
wsgi
""" WSGI config for geodj project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'geodj.settings') application = get_wsgi_application()
試したこと
heroku run python manage.py checkしても
System check identified no issues (0 silenced).となり問題なさそうです。
djangoアプリを作り直したところ、アプリのurl/adminとすると
デフォルトのログイン画面(自分で作ったログイン画面ではない)が表示されます。
管理画面で登録したデータがherokuのデータベースに登録できていることを
確認できました。
管理画面からサイト画面に移るとserver error(500)となり、
上記と同じエラーログがでています。
管理画面が見れて、indexなどが見れないということはpathがおかしいのでしょうか?
url
#url.py from django.contrib import admin from django.urls import include, path from map.views import areaViewSet,upl_imgsViewSet from rest_framework.routers import DefaultRouter from map.views import index, GeojsonAPIView, upload # 画像表示用 from . import settings from django.contrib.staticfiles.urls import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns router = DefaultRouter() router.register('area', areaViewSet)# area用 router.register('upl_imgs', upl_imgsViewSet)# upl_imgs用 urlpatterns = [ path('admin/', admin.site.urls), path('api/', include(router.urls)), path('accounts/', include('django.contrib.auth.urls')), path('', index, name='map_index'), path('map/geojson/', GeojsonAPIView.as_view(), name='geojson_view'), path('upload/', upload, name='upload'), ] # 画像表示用 urlpatterns += staticfiles_urlpatterns() urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
tree
C:. ├─deploy | ├─__init.py | ├─asgi.py | ├─local_settings.py | ├─settings.py | ├─urls.py | ├─wsgi.py ├─map │ ├─data │ ├─migrations │ ├─static │ │ └─map │ │ ├─css │ │ └─js │ ├─templates │ │ ├─map | | | ├─index.html | | | ├─upload.html │ │ └─registration | | | └─login.html ├─media │ └─image ├─static ├─staticfiles │ ├─admin │ ├─gis │ ├─leaflet │ ├─map │ └─rest_framework ├─__init__.py ├─manage.py ├─Procfile ├─requirements.txt ├─runtime.txt └─.gitignore
補足情報(FW/ツールのバージョンなど)
windows10
python3.6.10
django3.0.7
まだ回答がついていません
会員登録して回答してみよう