【发布时间】:2023-03-19 03:43:01
【问题描述】:
我成功地使用 Heroku 部署了我的 Django 项目,但是当我查看我的应用时,我收到一个错误页面
应用程序错误应用程序和您的页面发生错误 无法送达。如果您是应用程序所有者,请检查您的日志 详情。您可以在 Heroku CLI 中使用以下命令完成此操作
heroku logs --tail
当我将它放入终端时,我会收到此消息
2021-03-16T08:50:34.762969+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [4] [INFO] Starting gunicorn 20.0.4
2021-03-16T08:50:34.763493+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [4] [INFO] Listening at: http://0.0.0.0:55178 (4)
2021-03-16T08:50:34.763587+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [4] [INFO] Using worker: sync
2021-03-16T08:50:34.767113+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [8] [INFO] Booting worker with pid: 8
2021-03-16T08:50:34.770278+00:00 app[web.1]: Failed to find attribute 'application' in 'ourUI'.
2021-03-16T08:50:34.770403+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-03-16T08:50:34.794976+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [9] [INFO] Booting worker with pid: 9
2021-03-16T08:50:34.799785+00:00 app[web.1]: Failed to find attribute 'application' in 'ourUI'.
2021-03-16T08:50:34.799990+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-03-16T08:50:34.904166+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [4] [INFO] Shutting down: Master
2021-03-16T08:50:34.904279+00:00 app[web.1]: [2021-03-16 08:50:34 +0000] [4] [INFO] Reason: App failed to load.
2021-03-16T08:50:37.000000+00:00 app[api]: Build succeeded
2021-03-16T08:50:39.982849+00:00 heroku[web.1]: Starting process with command `gunicorn ourUI`
2021-03-16T08:50:42.245442+00:00 heroku[web.1]: Process exited with status 4
2021-03-16T08:50:42.310353+00:00 heroku[web.1]: State changed from starting to crashed
2021-03-16T08:50:42.140009+00:00 app[web.1]: [2021-03-16 08:50:42 +0000] [4] [INFO] Starting gunicorn 20.0.4
2021-03-16T08:50:42.140941+00:00 app[web.1]: [2021-03-16 08:50:42 +0000] [4] [INFO] Listening at: http://0.0.0.0:31341 (4)
2021-03-16T08:50:42.141087+00:00 app[web.1]: [2021-03-16 08:50:42 +0000] [4] [INFO] Using worker: sync
2021-03-16T08:50:42.145144+00:00 app[web.1]: [2021-03-16 08:50:42 +0000] [8] [INFO] Booting worker with pid: 8
2021-03-16T08:50:42.148479+00:00 app[web.1]: Failed to find attribute 'application' in 'ourUI'.
2021-03-16T08:50:42.148628+00:00 app[web.1]: [2021-03-16 08:50:42 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-03-16T08:50:42.182612+00:00 app[web.1]: [2021-03-16 08:50:42 +0000] [4] [INFO] Shutting down: Master
2021-03-16T08:50:42.182707+00:00 app[web.1]: [2021-03-16 08:50:42 +0000] [4] [INFO] Reason: App failed to load.
2021-03-16T08:51:10.997193+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hdpcapp.herokuapp.com request_id=ff5bdf78-e5b6-41cf-80e6-1bdf1d5f81f5 fwd="51.39.244.104" dyno= connect= service= status=503 bytes= protocol=https
这是我的 Procfile
web: gunicorn ourUI
requirement.txt
asgiref==3.3.1
Django==3.1.7
gunicorn==20.0.4
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0
ourUI 是我的 Django 项目
ourUI/setting.py
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().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 = 'a-skd+xzh4&dka$6(wl5q*#7%b%q8a%aijy70cc#(5mw6+y25-'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['hdpcapp.herokuapp.com', '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',
'TheUI'
]
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',
]
ROOT_URLCONF = 'ourUI.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 = 'ourUI.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',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/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.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'dtsticfiles')
STATIC_URL = '/static/'
ourUI/wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ourUI.settings')
application = get_wsgi_application()
我是 Django 和 heroku 的新手,希望能找到解决方案
【问题讨论】: