After uploading django to heroku, server error 500 occurs.

Asked 2 years ago, Updated 2 years ago, 77 views

I made a simple blog with django now and posted it on heroku. However, server error (500) error occurs on some pages.

First of all, the server error (500) error occurs on the Google login page, the e-mail created with allauth, and the django admin page.

File settings.py.

import os
import dj_database_url

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

SECRET_KEY = 'Original Present'
DEBUG = False

ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
    'blog',
    'basecamp',


    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.sites',
    'django.contrib.staticfiles',
    'django_extensions',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',

    'markdownx',
    'crispy_forms',
    'storages',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'my_site_prj.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'my_site_prj.wsgi.application'
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
DATABASES['default'].update(dj_database_url.config(conn_max_age=500))
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 = 'Asia/Seoul'

USE_I18N = True

USE_L10N = True

USE_TZ = True

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'none'

# # STATIC_URL = '/static/'
# # STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

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

from datetime import datetime

MARKDOWNX_MEDIA_PATH = datetime.now().strftime('markdownx/%Y/%m/%d')

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = '/blog/'

AWS_ACCESS_KEY_ID = ' # Original Present
AWS_SECRET_ACCESS_KEY = '' #Original Present
AWS_REGION = 'ap-northeast-2'
AWS_STORAGE_BUCKET_NAME = 'inflearn-django'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.%s.amazonaws.com' % (AWS_STORAGE_BUCKET_NAME, AWS_REGION)
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}
DEFAULT_FILE_STORAGE = 'my_site_prj.asset_storage.MediaStorage'

The requirements.txt file.

beautifulsoup4==4.8.1
boto3==1.10.45
botocore==1.13.45
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
cryptography==2.8
defusedxml==0.6.0
dj-database-url==0.5.0
Django==2.2
django-allauth==0.41.0
django-crispy-forms==1.8.1
django-extensions==2.2.5
django-markdownx==2.0.28
django-storages==1.8
docutils==0.15.2
gunicorn==20.0.4
idna==2.8
jmespath==0.9.4
Markdown==3.1.1
oauthlib==3.1.0
Pillow==6.2.1
psycopg2-binary==2.8.4
pycparser==2.19
python-dateutil==2.8.1
python3-openid==3.1.0
pytz==2019.3
requests==2.22.0
requests-oauthlib==1.3.0
s3transfer==0.2.1
six==1.13.0
soupsieve==1.9.5
sqlparse==0.3.0
urllib3==1.25.7
whitenoise==5.0.1

runtime.txt is python-3.7.2

Procfile is web: gunicorn my_site_prj.wsgi.

The page didn't get an error from the beginning, but only a few services got an error I don't know what to show. ㅜ If you need other parts besides the ones I showed you, I'll update it. Please give me a lot of help. Thank you ㅜ<

I turned on the debug and posted it on heroku, so I saw the error Obviously, localhost used to have accounts/login/ and /accounts/google/login/, /admin/login/doesnotexist says url is missing. Why can't I find url if I only go up to heroku?

This is urls in config.

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('blog/', include('blog.urls')),
    path('admin/', admin.site.urls),
    path('markdownx/', include('markdownx.urls')),
    path('accounts/', include('allauth.urls')),
    path('', include('basecamp.urls')),
]

django heroku

2022-09-22 19:19

1 Answers

I added SITE_ID=1 to settings.py and the server error is gone!


2022-09-22 19:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.