将django应用程序部署到heroku时接收服务器错误(500)

yyhrrdl8  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(450)

几天来,我一直在努力将我的站点部署到heroku。关于这个主题,我提到了许多其他堆栈溢出问题,例如:
django heroku服务器错误(500),当我将debug-false设置为true时,它工作正常
heroku/django部署:为什么成功部署和静态收集会出现错误500?
作为参考,我在做这件事时遵循了heroku关于django应用程序部署的指南。下面是我的这个困境的相关代码。
基本设置.py

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.

BASE_DIR = Path(__file__).resolve().parent.parent.parent

# Quick-start development settings - unsuitable for production

# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = thekey

# SECURITY WARNING: don't run with debug turned on in production!

DEBUG = False

ALLOWED_HOSTS = ['[REDACTED].herokuapp.com','localhost','127.0.0.1']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'store.apps.StoreConfig',
    'basket.apps.BasketConfig',
    'account.apps.AccountConfig',
    'orders.apps.OrdersConfig',
    'checkout.apps.CheckoutConfig',
    'mptt',
]

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

WSGI_APPLICATION = 'hifive.wsgi.application'

# Database

# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = (
    os.path.join(BASE_DIR, "static")
)

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

# Basket session ID

BASKET_SESSION_ID = 'basket'

# Email setting

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# whitenoice static config goes here

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

程序文件

release: python manage.py migrate
web: gunicorn hifive.wsgi --preload --log-file -

py(使用django环境包,行为类似于旧的django heroku包)

"""
Production Settings for Heroku
"""

import environ

# If using in your own project, update the project namespace below

from projectname.settings.base_settings import *

env = environ.Env(
    # set casting, default value
    DEBUG=(bool, False)
)

# False if not in os.environ

DEBUG = env('DEBUG')

# Raises django's ImproperlyConfigured exception if SECRET_KEY not in os.environ

SECRET_KEY = env('SECRET_KEY')

ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')

# Parse database connection url strings like psql://user:pass@127.0.0.1:8458/db

DATABASES = {
    # read os.environ['DATABASE_URL'] and raises ImproperlyConfigured exception if not found
    'default': env.db(),
}

最近的heroku日志

2021-07-09T18:21:24.244522+00:00 app[web.1]: [2021-07-09 18:21:24 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-07-09T18:21:24.246961+00:00 app[web.1]: [2021-07-09 18:21:24 +0000] [4] [WARNING] Worker with pid 8 was terminated due to signal 15
2021-07-09T18:21:24.448574+00:00 app[web.1]: [2021-07-09 18:21:24 +0000] [4] [INFO] Shutting down: Master
2021-07-09T18:21:24.616313+00:00 heroku[web.1]: Process exited with status 0
2021-07-09T18:21:40.928920+00:00 heroku[web.1]: Starting process with command `gunicorn hifive.wsgi --preload --log-file -`
2021-07-09T18:21:48.514793+00:00 app[web.1]: [2021-07-09 18:21:48 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-07-09T18:21:48.515601+00:00 app[web.1]: [2021-07-09 18:21:48 +0000] [4] [INFO] Listening at: http://0.0.0.0:16532 (4)
2021-07-09T18:21:48.519986+00:00 app[web.1]: [2021-07-09 18:21:48 +0000] [4] [INFO] Using worker: sync
2021-07-09T18:21:48.530310+00:00 app[web.1]: [2021-07-09 18:21:48 +0000] [8] [INFO] Booting worker with pid: 8
2021-07-09T18:21:48.586400+00:00 app[web.1]: [2021-07-09 18:21:48 +0000] [9] [INFO] Booting worker with pid: 9
2021-07-09T18:21:48.604573+00:00 heroku[web.1]: State changed from starting to up
2021-07-09T18:21:56.854782+00:00 app[web.1]: 10.63.102.120 - - [09/Jul/2021:18:21:56 +0000] "GET / HTTP/1.1" 500 145 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
2021-07-09T18:21:56.855004+00:00 heroku[router]: at=info method=GET path="/" host=[REDACTED].herokuapp.com request_id=1781abc4-ea2d-4a6f-8d5a-8d6978e3f796 fwd="146.115.104.181" dyno=web.1 connect=7ms service=2312ms status=500 bytes=403 protocol=https
2021-07-09T18:55:29.769232+00:00 heroku[web.1]: Idling
2021-07-09T18:55:29.772171+00:00 heroku[web.1]: State changed from up to down
2021-07-09T18:55:31.082908+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-07-09T18:55:31.292387+00:00 app[web.1]: [2021-07-09 18:55:31 +0000] [4] [INFO] Handling signal: term
2021-07-09T18:55:31.292906+00:00 app[web.1]: [2021-07-09 18:55:31 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-07-09T18:55:31.320569+00:00 app[web.1]: [2021-07-09 18:55:31 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-07-09T18:55:31.699981+00:00 app[web.1]: [2021-07-09 18:55:31 +0000] [4] [INFO] Shutting down: Master
2021-07-09T18:55:31.914898+00:00 heroku[web.1]: Process exited with status 0
2021-07-10T11:01:07.000000+00:00 app[api]: Build started by user [REDACTED]@gmail.com
2021-07-10T11:02:33.756595+00:00 app[api]: Running release v21 commands by user [REDACTED]@gmail.com
2021-07-10T11:02:33.756595+00:00 app[api]: Deploy 5b3c4ba1 by user [REDACTED]@gmail.com
2021-07-10T11:02:34.158924+00:00 app[api]: Starting process with command `/bin/sh -c 'if curl $HEROKU_RELEASE_LOG_STREAM --silent --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then
2021-07-10T11:02:34.158924+00:00 app[api]: chmod u+x /tmp/log-stream
2021-07-10T11:02:34.158924+00:00 app[api]: /tmp/log-stream /bin/sh -c '"'"'python manage.py migrate'"'"'
2021-07-10T11:02:34.158924+00:00 app[api]: else
2021-07-10T11:02:34.158924+00:00 app[api]: python manage.py migrate
2021-07-10T11:02:34.158924+00:00 app[api]: fi'` by user [REDACTED]@gmail.com
2021-07-10T11:02:46.552302+00:00 heroku[release.8726]: Starting process with command `/bin/sh -c 'if curl https://heroku-release-output.s3.amazonaws.com/log-stream?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ3LIQ2SWG7V76SVQ%2F20210710%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210710T110234Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=7047143c51310764b25b9b542e07ef0a320a4840d8f2e9b1390a67181543e364 --silent --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then
2021-07-10T11:02:47.212992+00:00 heroku[release.8726]: State changed from starting to up
2021-07-10T11:02:49.914196+00:00 app[release.8726]: Operations to perform:
2021-07-10T11:02:49.914206+00:00 app[release.8726]: Apply all migrations: account, admin, auth, checkout, contenttypes, orders, sessions, store
2021-07-10T11:02:49.938375+00:00 app[release.8726]: Running migrations:
2021-07-10T11:02:49.938376+00:00 app[release.8726]: No migrations to apply.
2021-07-10T11:02:50.249379+00:00 heroku[release.8726]: Process exited with status 0
2021-07-10T11:02:50.337703+00:00 heroku[release.8726]: State changed from up to complete
2021-07-10T11:02:51.862106+00:00 app[api]: Release v21 created by user [REDACTED]@gmail.com
2021-07-10T11:02:52.474927+00:00 heroku[web.1]: State changed from down to starting
2021-07-10T11:02:56.000000+00:00 app[api]: Build succeeded
2021-07-10T11:03:06.594414+00:00 heroku[web.1]: Starting process with command `gunicorn hifive.wsgi --preload --log-file -`
2021-07-10T11:03:10.041463+00:00 app[web.1]: [2021-07-10 11:03:10 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-07-10T11:03:10.042372+00:00 app[web.1]: [2021-07-10 11:03:10 +0000] [4] [INFO] Listening at: http://0.0.0.0:57946 (4)
2021-07-10T11:03:10.042475+00:00 app[web.1]: [2021-07-10 11:03:10 +0000] [4] [INFO] Using worker: sync
2021-07-10T11:03:10.048960+00:00 app[web.1]: [2021-07-10 11:03:10 +0000] [8] [INFO] Booting worker with pid: 8
2021-07-10T11:03:10.053062+00:00 app[web.1]: [2021-07-10 11:03:10 +0000] [9] [INFO] Booting worker with pid: 9
2021-07-10T11:03:10.887530+00:00 heroku[web.1]: State changed from starting to up
2021-07-10T11:03:30.263960+00:00 app[web.1]: 10.63.104.194 - - [10/Jul/2021:11:03:30 +0000] "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, 
like Gecko) Chrome/91.0.4472.124 Safari/537.36"
2021-07-10T11:03:30.264986+00:00 heroku[router]: at=info method=GET path="/" host=[REDACTED].herokuapp.com request_id=59d8fe15-39d2-4c4c-a310-db42018c9c9b fwd="98.118.105.83" dyno=web.1 connect=1ms service=557ms status=500 bytes=403 protocol=https
2021-07-10T11:29:57.576929+00:00 app[api]: Starting process with command `python manage.py migrate` by user [REDACTED]@gmail.com
2021-07-10T11:30:11.074996+00:00 heroku[run.5139]: State changed from starting to up
2021-07-10T11:30:11.079694+00:00 heroku[run.5139]: Awaiting client
2021-07-10T11:30:11.129997+00:00 heroku[run.5139]: Starting process with command `python manage.py migrate`
2021-07-10T11:30:18.414777+00:00 heroku[run.5139]: Process exited with status 0
2021-07-10T11:30:18.480456+00:00 heroku[run.5139]: State changed from up to complete
2021-07-10T11:33:31.796164+00:00 app[api]: Set DJANGO_DEBUG config vars by user [REDACTED]@gmail.com
2021-07-10T11:33:31.796164+00:00 app[api]: Running release v22 commands by user [REDACTED]@gmail.com
2021-07-10T11:33:32.335784+00:00 app[api]: Starting process with command `/bin/sh -c 'if curl $HEROKU_RELEASE_LOG_STREAM --silent --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then
2021-07-10T11:33:32.335784+00:00 app[api]: chmod u+x /tmp/log-stream
2021-07-10T11:33:32.335784+00:00 app[api]: /tmp/log-stream /bin/sh -c '"'"'python manage.py migrate'"'"'
2021-07-10T11:33:32.335784+00:00 app[api]: else
2021-07-10T11:33:32.335784+00:00 app[api]: python manage.py migrate
2021-07-10T11:33:32.335784+00:00 app[api]: fi'` by user [REDACTED]@gmail.com
2021-07-10T11:33:43.308237+00:00 heroku[release.2575]: Starting process with command `/bin/sh -c 'if curl https://heroku-release-output.s3.amazonaws.com/log-stream?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ3LIQ2SWG7V76SVQ%2F20210710%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210710T113332Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=f8dddd920ac062b5204f56360898ba12c0526b7b23df394a8f62777e709798db --silent --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then
2021-07-10T11:33:43.988281+00:00 heroku[release.2575]: State changed from starting to up
2021-07-10T11:33:47.079959+00:00 app[release.2575]: Operations to perform:
2021-07-10T11:33:47.079970+00:00 app[release.2575]: Apply all migrations: account, admin, auth, checkout, contenttypes, orders, sessions, store
2021-07-10T11:33:47.106575+00:00 app[release.2575]: Running migrations:
2021-07-10T11:33:47.106577+00:00 app[release.2575]: No migrations to apply.
2021-07-10T11:33:47.438883+00:00 heroku[release.2575]: Process exited with status 0
2021-07-10T11:33:47.503329+00:00 heroku[release.2575]: State changed from up to complete
2021-07-10T11:33:48.574628+00:00 app[api]: Release v22 created by user [REDACTED]@gmail.com
2021-07-10T11:33:48.984882+00:00 heroku[web.1]: Restarting
2021-07-10T11:33:49.001365+00:00 heroku[web.1]: State changed from up to starting
2021-07-10T11:33:51.000457+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-07-10T11:33:51.086147+00:00 app[web.1]: [2021-07-10 11:33:51 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-07-10T11:33:51.130130+00:00 app[web.1]: [2021-07-10 11:33:51 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-07-10T11:33:51.142070+00:00 app[web.1]: [2021-07-10 11:33:51 +0000] [4] [INFO] Handling signal: term
2021-07-10T11:33:51.162224+00:00 app[web.1]: [2021-07-10 11:33:51 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2021-07-10T11:33:51.163013+00:00 app[web.1]: [2021-07-10 11:33:51 +0000] [4] [WARNING] Worker with pid 8 was terminated due to signal 15
2021-07-10T11:33:51.248376+00:00 app[web.1]: [2021-07-10 11:33:51 +0000] [4] [INFO] Shutting down: Master
2021-07-10T11:33:51.710703+00:00 heroku[web.1]: Process exited with status 0
2021-07-10T11:34:04.636748+00:00 heroku[web.1]: Starting process with command `gunicorn hifive.wsgi --preload --log-file -`
2021-07-10T11:34:09.776118+00:00 app[web.1]: [2021-07-10 11:34:09 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-07-10T11:34:09.777118+00:00 app[web.1]: [2021-07-10 11:34:09 +0000] [4] [INFO] Listening at: http://0.0.0.0:40804 (4)
2021-07-10T11:34:09.777259+00:00 app[web.1]: [2021-07-10 11:34:09 +0000] [4] [INFO] Using worker: sync
2021-07-10T11:34:09.783991+00:00 app[web.1]: [2021-07-10 11:34:09 +0000] [8] [INFO] Booting worker with pid: 8
2021-07-10T11:34:09.793436+00:00 app[web.1]: [2021-07-10 11:34:09 +0000] [9] [INFO] Booting worker with pid: 9
2021-07-10T11:34:10.322938+00:00 heroku[web.1]: State changed from starting to up
2021-07-10T11:34:12.800333+00:00 heroku[router]: at=info method=GET path="/" host=[REDACTED].herokuapp.com request_id=031f5fc8-1bbb-4885-89d1-54551816606f fwd="98.118.105.83" dyno=web.1 connect=1ms service=948ms status=500 bytes=403 protocol=https
2021-07-10T11:34:12.801449+00:00 app[web.1]: 10.31.89.92 - - [10/Jul/2021:11:34:12 +0000] "GET / HTTP/1.1" 500 145 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"

最糟糕的是,每当我查看日志时,似乎没有错误,我不确定如何解决这个问题。任何关于如何解决这个问题的建议都将不胜感激。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题