如何解决无法将Django上传到带有Digital Ocean Apps的生产环境,“收集静态无输入”错误
我正在尝试使用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服务吗?非常感谢您如何克服此错误,如果您需要我的更多文档,请告诉我。
解决方法
您的DATABASES
设置似乎已配置用于本地开发,即指向您的localhost
。您需要为计划在Digital Ocean中使用的数据库指定HOST / PORT / PASSWORD。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。