在将Django应用程序部署到Heroku时发生Collectstatic错误 [英] Collectstatic error while deploying Django app to Heroku
问题描述
我正在尝试将Django应用程序部署到Heroku,它开始构建,下载和安装所有内容,但这就是我收集静态文件时所得到的结果。
$ python manage.py collectstatic --noinput
remote:Traceback(最近调用最后一个):
remote:文件manage.py,第10行,在< module>
remote:execute_from_command_line(sys.argv)
remote:文件/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py,行338,在execute_from_command_line
remote:utility.execute()
remote:File/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py ,第330行,执行
remote:self.fetch_command(子命令).run_from_argv(self.argv)
remote:文件/app/.heroku/python/lib/python2.7/site- packages / django / core / management / base.py,第390行,在run_from_argv
remote:self.execute(* args,** cmd_options)
remote:File/app/.heroku/python /lib/python2.7/site-packages/django/core/management/base.py,第441行,执行
remote:output = self.handle(* args,** options)
remote:File/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py,li ne 168,处理
remote:collected = self.collect()
remote:File/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/管理/命令/ collectstatic.py,第98行,收集
remote:用于路径,存储在finder.list(self.ignore_patterns)中:
remote:File/app/.heroku/python/ lib / python2.7 / site-packages / django / contrib / staticfiles / finders.py,第112行,列表中
remote:for utils.get_files(storage,ignore_patterns)中的路径:
remote:文件/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py,第28行,在get_files
remote:directories,files = storage.listdir(位置)
remote:文件/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py,行300,在listdir
remote:进入os.listdir(路径):
remote:OSError:[Errno 2]没有这样的文件或目录:'/ app / blogproject /静态'
远程:
远程:!运行'$ python manage.py collectstatic --noinput'时出错。
remote:详细信息请参阅上面的回溯。
remote:
remote:您可能需要更新应用程序代码才能解决此错误。
remote:或者,您可以禁用此应用程序的collectstatic:
remote:
remote:$ heroku config:set DISABLE_COLLECTSTATIC = 1
remote:
remote:https: //devcenter.heroku.com/articles/django-assets
remote:
remote:!推送被拒绝,未能编译Python应用程序
remote:
remote:正在验证部署...
remote:
remote:!拒绝推销航程。
这是整个settings.py文件
#在这样的项目中构建路径:os.path.join(BASE_DIR,...)
import os
import dj_database_url
BASE_DIR = os.path.dirname(os.path.dirname(__ file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__ file__))
#快速启动开发设置 - 不适合制作
#请参阅https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
#安全警告:保密密钥中使用的密钥!
SECRET_KEY ='*********************'
#安全警告:不要在打开调试时运行生产!
DEBUG = True
#应用程序定义
INSTALLED_APPS =(
'django.contrib.admin',
' django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django。 contrib.staticfiles',
'blog',
'custom_user',
'django_markdown',$ b $'parsley',
)
#### AUTH ###
AUTH_USER_MODEL ='custom_user.CustomUser'
AUTHENTICATION_BACKENDS =(
'custom_user.backends.CustomUserAuth',
'django.contrib.auth.backends.ModelBackend',
#'django.contrib.auth.backends.RemoteUserBackend',
)
######## #####
####电子邮件###
EMAIL_USE_TLS =真
EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend '
EMAIL_HOST ='smtp.gmail.com'
EMAIL_HOST_PASSWORD ='***'#my gmail密码
EMAIL_HOST_USER ='voyage.pin@gmail.com'#my gmail用户名
DEFAULT_FROM_EMAIL ='voyage.pin@gmail.com'
SERVER_EMAIL ='voyage.pin@gmail.com'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
##############
MIDDLEWARE_CLASSES =(
'django.contrib .sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware ',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF ='blogproject.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 ='blogproject.wsgi.application'
#数据库
#https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {$ b $'default':{
'ENGINE':'django.db.backends.postgresql_psycopg2',
'NAME':'blogproject',$ b $'USER':'***',
'PASSWORD': '***',
'HOST':'localhost',
'PORT':'',
}
}
#国际化
#https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE ='en-us'
TIME_ZONE ='UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
#使用$ DATABASE_URL更新数据库配置。
db_from_env = dj_database_url.config(conn_max_age = 500)
DATABASES ['default']。update(db_from_env)
#请求'X-Forwarded-Proto' .is_secure()
SECURE_PROXY_SSL_HEADER =('HTTP_X_FORWARDED_PROTO','https')
#允许所有主机标题
ALLOWED_HOSTS = ['*']
#静态文件(CSS,JavaScript,图像)
#https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_ROOT = os.path。 join(PROJECT_ROOT,'staticfiles')
STATIC_URL ='/ static /'
#collectstatic找到静态文件的附加位置。
STATICFILES_DIRS =(
os.path.join(PROJECT_ROOT,'static'),
)
#简化的静态文件服务。
#https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE ='whitenoise.django.GzipManifestStaticFilesStorage'
这是项目结构
blog-project - blog - 迁移
- 静态
- 模板
- blogproject
- blogprojectenv
- custom_user $ b $ - media
- 。 git
有什么想法?
我今天刚刚更新为Django 1.10,并且出现了完全相同的问题。
您的静态设置与我的一样。
这对我有用,运行以下命令:
-
禁用部署期间的collectstatic
heroku config:set DISABLE_COLLECTSTATIC = 1 code $
部署
git push heroku master -
运行迁移(django 1.10添加至少一个)
heroku run python manage.py migrate
-
使用bower运行collectstatic
heroku run'bower install --config.interactive = false; grunt prep; python manage.py collectstatic --noinput'
-
启用collecstatic以备将来部署
heroku config:unset DISABLE_COLLECTSTATIC
manage.py collectstatic
从现在开始正常
I'm trying to deploy a Django app to Heroku, it starts to build, download and installs everything, but that's what I get when it comes to collecting static files
$ python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "manage.py", line 10, in <module>
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
remote: self.execute(*args, **cmd_options)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
remote: output = self.handle(*args, **options)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
remote: collected = self.collect()
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
remote: for path, storage in finder.list(self.ignore_patterns):
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
remote: for path in utils.get_files(storage, ignore_patterns):
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
remote: directories, files = storage.listdir(location)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 300, in listdir
remote: for entry in os.listdir(path):
remote: OSError: [Errno 2] No such file or directory: '/app/blogproject/static'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote:
remote: ! Push rejected, failed to compile Python app
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to pin-a-voyage.
This is the whole settings.py file
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import dj_database_url
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*********************'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'custom_user',
'django_markdown',
'parsley',
)
#### AUTH ###
AUTH_USER_MODEL = 'custom_user.CustomUser'
AUTHENTICATION_BACKENDS = (
'custom_user.backends.CustomUserAuth',
'django.contrib.auth.backends.ModelBackend',
# 'django.contrib.auth.backends.RemoteUserBackend',
)
#############
#### EMAIL ###
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = '***' #my gmail password
EMAIL_HOST_USER = 'voyage.pin@gmail.com' #my gmail username
DEFAULT_FROM_EMAIL = 'voyage.pin@gmail.com'
SERVER_EMAIL = 'voyage.pin@gmail.com'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
##############
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'blogproject.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 = 'blogproject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'blogproject',
'USER': '***',
'PASSWORD': '***',
'HOST': 'localhost',
'PORT': '',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
This is the structure of the project
blog-project -- blog -- migrations
-- static
-- templates
-- blogproject
-- blogprojectenv
-- custom_user
-- media
-- .git
Any thoughts?
I just updated to Django 1.10 today and had the exact same problem. Your static settings are identical to mine as well.
This worked for me, run the following commands:
disable the collectstatic during a deploy
heroku config:set DISABLE_COLLECTSTATIC=1
deploy
git push heroku master
run migrations (django 1.10 added at least one)
heroku run python manage.py migrate
run collectstatic using bower
heroku run 'bower install --config.interactive=false;grunt prep;python manage.py collectstatic --noinput'
enable collecstatic for future deploys
heroku config:unset DISABLE_COLLECTSTATIC
try it on your own (optional)
heroku run python manage.py collectstatic
future deploys should work as normal from now on
这篇关于在将Django应用程序部署到Heroku时发生Collectstatic错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!