【发布时间】:2020-10-16 23:59:02
【问题描述】:
我正在尝试使用 Digital Oceans Apps 将我的 django 应用程序上传到生产服务器。但是我不断收到这个错误,我已经尝试了一切。我看到在下面的日志中,有一个$ heroku config:set DISABLE_COLLECTSTATIC=1,我之前将此应用程序注册为heroku git,但从未将其投入生产,现在已经删除了Heroku 的所有痕迹。我对为什么会收到此错误感到困惑。
下面是settings.py 和我的数字海洋日志
#settings.py
"""
Django settings for stockbuckets project.
Generated by 'django-admin startproject' using Django 3.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
import dj_database_url
# 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 = os.environ.get('SECRET_KEY_DJANGO_STOCKBUCKETS')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['0.0.0.0', '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',
'home.apps.HomeConfig',
'django_plotly_dash.apps.DjangoPlotlyDashConfig',
'dpd_static_support',
'channels',
'channels_redis',
'bootstrap4',
'blog',
]
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_plotly_dash.middleware.BaseMiddleware',
'django_plotly_dash.middleware.ExternalRedirectionMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'stockbuckets.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['stockbuckets/templates', 'home/templates', 'blog/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 = 'stockbuckets.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',
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'sb',
'USER' : 'postgres',
'PASSWORD' : '0',
'HOST' : 'localhost'
}
}
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)
# 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
CRISPY_TEMPLATE_PACK = 'bootstrap4'
ASGI_APPLICATION = 'stockbuckets.routing.application'
CHANNEL_LAYERS = {
'default' : {
'BACKEND': 'channels_redis_core.RedisChannelLayer',
'CONFIG' : {
'hosts' : [('127.0.0.1',6379),],
}
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django_plotly_dash.finders.DashAssetFinder',
'django_plotly_dash.finders.DashComponentFinder',
'django_plotly_dash.finders.DashAppDirectoryFinder',
]
PLOTLY_COMPONENTS = [
# Common components
'dash_core_components',
'dash_html_components',
'dash_renderer',
# django-plotly-dash components
'dpd_components',
# static support if serving local assets
'dpd_static_support',
# Other components, as needed
'dash_bootstrap_components',
]
X_FRAME_OPTIONS = 'SAMEORIGIN'
STATICFILES_LOCATION = 'static'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'stockbuckets/static')
]
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'
# STATIC_URL = '/static/'
# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# VENV_PATH = os.path.dirname(BASE_DIR)
# STATIC_ROOT = os.path.join(VENV_PATH, 'static_root')
# Additional locations of static files
# STATICFILES_DIRS = (
# # Put strings here, like "/home/html/static" or "C:/www/django/static".
# # Always use forward slashes, even on Windows.
# # Don't forget to use absolute paths, not relative paths.
# os.path.join(BASE_DIR, 'static'),
# )
# STATICFILES_FINDERS = (
# 'django.contrib.staticfiles.finders.FileSystemFinder',
# 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# # django.contrib.staticfiles.finders.DefaultStorageFinder',
# )
日志:
stockbuckets | 18:45:18 -----> $ python manage.py collectstatic --noinput
stockbuckets | 18:45:20 OpenBLAS WARNING - could not determine the L2 cache size on this system, assuming 256k
stockbuckets | 18:45:20 Connecting to the PostgreSQL database...
stockbuckets | 18:45:20 could not connect to server: Connection refused
stockbuckets | 18:45:20 Is the server running on host "localhost" (::1) and accepting
stockbuckets | 18:45:20 TCP/IP connections on port 5432?
stockbuckets | 18:45:20 could not connect to server: Connection refused
stockbuckets | 18:45:20 Is the server running on host "localhost" (127.0.0.1) and accepting
stockbuckets | 18:45:20 TCP/IP connections on port 5432?
stockbuckets | 18:45:21
stockbuckets | 18:45:21 ! Error while running '$ python manage.py collectstatic --noinput'.
stockbuckets | 18:45:21 See traceback above for details.
stockbuckets | 18:45:21
stockbuckets | 18:45:21 You may need to update application code to resolve this error.
stockbuckets | 18:45:21 Or, you can disable collectstatic for this application:
stockbuckets | 18:45:21
stockbuckets | 18:45:21 $ heroku config:set DISABLE_COLLECTSTATIC=1
stockbuckets | 18:45:21
stockbuckets | 18:45:21 https://devcenter.heroku.com/articles/django-assets
stockbuckets | 18:45:21 ERROR: failed to build: exit status 1
stockbuckets | 18:45:21 ! Build failed (exit code 7)
我看到其他人提到了确切的问题here,但答案涉及使用 Docker,(传入的愚蠢问题)这不会是多余的,因为我正在使用 Digital Ocean 的新 PaaS 服务?非常感谢我如何克服此错误,如果您需要我的更多文档,请告诉我。
【问题讨论】:
标签: python django digital-ocean