Home>

When I do git push heroku main and heroku open, I get a server error (500). When I check the logs on heroku logs, it seems that an error has occurred on the login screen of django, but there is no message like 〇〇ERROR, and I do not know how to deal with it.
Thanks for your guidance.

It works locally without any errors.
migrate and createsupruser have already been implemented.

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 = app name.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 = app name.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
Corresponding source code
"" "
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 screen display settings
admin.AdminSite.site_title ='Login page'
admin.AdminSite.site_header ='Administrative screen'
admin.AdminSite.index_title ='Menu'
### Login related
LOGIN_URL ='/ accounts/login' #<-Login URL
LOGIN_REDIRECT_URL ='/' #<-Redirect to top page after login
LOGOUT_REDIRECT_URL ='/' #<-Redirect to top page after logout
## osgeo4w moved to 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 = [
    "app name"
]

#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',
    Added'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#Time out 10 hours after login
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') # Originally static
STATICFILES_DIRS = (os.path.join (BASE_DIR,'static'),) # Originally map/atatic
# ↓ heroku added
STATICFILES_STORAGE ='whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_ROOT = os.path.join (BASE_DIR,'media')
MEDIA_URL ='/ media /'
For #heroku
try: 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')
web: gunicorn geodj.wsgi --log-file-


requirements.txt

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 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_applicationos.environ.setdefault ('DJANGO_SETTINGS_MODULE','geodj.settings')
application = get_wsgi_application ()
What I tried

heroku run python manage.py check
System check identified no issues (0 silenced). It seems that there is no problem.

After recreating the django app, if you use the app url/admin
The default login screen (not your own login screen) is displayed.
That the data registered on the management screen can be registered in the heroku database
confirmed.
When moving from the management screen to the site screen, a server error (500) occurs and
I get the same error log as above.
Is it wrong with the path if you can see the management screen and not the index etc.?

# 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
# For image display
from. import settings
from django.contrib.staticfiles.urls import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
router = DefaultRouter ()
for router.register ('area', areaViewSet) # area
router.register ('upl_imgs', upl_imgsViewSet) # for 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'),
]
# For image display
urlpatterns + = staticfiles_urlpatterns ()
urlpatterns + = static (settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
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
├─ static files
│ ├─admin
│ ├─gis
│ ├─ leaflet
│ ├─ map
│ └─ rest_framework
├─__init__.py
├─ manage.py
├─Procfile
├─requirements.txt
├─runtime.txt
└─.gitignore
Supplementary information (FW/tool version, etc.)

windows10
python3.6.10
django 3.0.7

  • Answer # 1

    The cause was a mistake in the extension written in the html file.

    <p>.ico is wrong
    <p>.png is the correct answer


    The reason why I found this is that when I displayed the error with DEBUG = False by referring to the following site, it was "Value error" in the above part.

    Reference site
    https://qiita.com/yuu-eguci/items/a1e4b0a2f238d5ccc985

    Modification place;
    Add the following to the end of settings.py

    from django.views.decorators.csrf import requires_csrf_token
    from django.http import (
        HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotFound,
        HttpResponseServerError,)
    @requires_csrf_token
    def my_customized_server_error (request, template_name = '500.html'):
        import sys
        from django.views import debug
        error_html = debug.technical_500_response (request, * sys.exc_info ()). content
        return HttpResponseServerError (error_html)


    Add the following to the end of url.py

    from map.views import my_customized_server_error
    handler500 = my_customized_server_error


    If you do not know the cause of the error with DEBUG = False, please try it.