Reputation: 777
Hello and excuse my english
This error is weird until now I was able to push my Django app and database to heroku, this was my configuration
project structure:
.
├── apps
│ ├── home
│ │ ├── admin.py
│ │ ├── admin.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── models.pyc
│ │ ├── templates
│ │ ├── tests.py
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ ├── views.py
│ │ └── views.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── inventario
│ │ ├── admin.py
│ │ ├── admin.pyc
│ │ ├── forms.py
│ │ ├── forms.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── models.pyc
│ │ ├── templates
│ │ ├── tests.py
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ ├── views.py
│ │ └── views.pyc
│ ├── ordenes_trabajo
│ │ ├── admin.py
│ │ ├── admin.pyc
│ │ ├── forms.py
│ │ ├── forms.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── models.pyc
│ │ ├── templates
│ │ ├── tests.py
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ ├── views.py
│ │ └── views.pyc
│ ├── sucursales
│ │ ├── admin.py
│ │ ├── admin.pyc
│ │ ├── forms.py
│ │ ├── forms.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── models.pyc
│ │ ├── templates
│ │ ├── tests.py
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ ├── views.py
│ │ └── views.pyc
│ ├── usuarios
│ │ ├── admin.py
│ │ ├── admin.pyc
│ │ ├── forms.py
│ │ ├── forms.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── models.pyc
│ │ ├── templates
│ │ ├── tests.py
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ ├── views.py
│ │ └── views.pyc
│ └── ventas_cotizaciones
│ ├── admin.py
│ ├── admin.pyc
│ ├── forms.py
│ ├── forms.pyc
│ ├── htmltopdf.py
│ ├── htmltopdf.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── migrations
│ ├── models.py
│ ├── models.pyc
│ ├── templates
│ ├── tests.py
│ ├── urls.py
│ ├── urls.pyc
│ ├── views.py
│ └── views.pyc
├
├── __init__.py
├── manage.py
├── prerequirements_install.txt
├── Procfile
├── proyecto_www
│ ├── db.sqlite3
│ ├── __init__.py
│ ├
│ ├── README.md
│ ├── settings
│ │ ├── base.py
│ │ ├── base.pyc
│ │ ├── __init__.py
│ │ ├
│ │ ├── local.py
│ │ ├
│ │ ├── production.py
│ │ ├── staging.py
│ │ └── staging.pyc
│ ├── urls.py
│ ├
│ ├── wsgi.py
│ └
├── requirements.txt
├── static
I splited the settings like this:
settings/base.py
from unipath import Path
import os
BASE_DIR = Path(__file__).ancestor(3)
# 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 = 'THE SECRET KEY OF MY APP'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
DJANGO_APPS = (
...
)
LOCAL_APPS = (
...
)
THIRD_PARTY_APPS = (
...
)
INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS + THIRD_PARTY_APPS
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',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
)
ROOT_URLCONF = 'proyecto_www.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 = 'proyecto_www.wsgi.application'
STATIC_URL = '/static/'
STATICFILES_DIRS=(BASE_DIR,'static',)
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR.child('media')
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'es'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_METHODS = (
...
)
And the settings/staging.py, which I use for deployment
from .base import *
DEBUG_TOOLBAR_PATCH_SETTINGS = False
DEBUG = True
TEMPLATE_DEBUG = True
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
...
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_ROOT = 'staticfiles'
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
My Procfile is:
web: gunicorn proyecto_www.wsgi --log-file -
My wsgi.py is:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proyecto_www.settings.staging")
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())
The initial error was "The SECRET_KEY setting must not be empty"
So I followed the answer here Django. Using multiple settings files with Heroku
And use the command:
heroku config:set DJANGO_SETTINGS_MODULE=proyecto_www.settings.staging
And now I receive this error:
remote: Successfully installed BeautifulSoup-3.2.1 Django-1.8.4 Pillow-3.0.0 PyPDF2-1.25.1 Unipath-1.1 dj-database-url-0.3.0 dj-static-0.0.6 django-cors-headers-1.1.0 django-datatable-view-0.8.3 django-toolbelt-0.0.1 gunicorn-19.4.1 html5lib-0.9999999 psycopg2-2.6.1 python-dateutil-2.4.2 reportlab-3.2.0 six-1.10.0 static3-0.6.1 wheel-0.24.0 whitenoise-2.0.6 xhtml2pdf-0.0.6 xlwt-0.7.4
remote:
remote: $ python manage.py collectstatic --noinput
remote: Post-processing 'tmp/cache/tmp_app_dir/vendor/ruby-2.3.0/lib/ruby/2.3.0/rdoc/generator/template/darkfish/css/rdoc.css' failed!
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 393, 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 444, 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 120, in collect
remote: raise processed
remote: whitenoise.django.MissingFileError: The file 'tmp/cache/tmp_app_dir/vendor/ruby-2.3.0/lib/ruby/2.3.0/rdoc/generator/template/darkfish/css/images/wrench_orange.png' could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7fe55e8ec4d0>.
remote: The CSS file 'tmp/cache/tmp_app_dir/vendor/ruby-2.3.0/lib/ruby/2.3.0/rdoc/generator/template/darkfish/css/rdoc.css' references a file which could not be found:
remote: tmp/cache/tmp_app_dir/vendor/ruby-2.3.0/lib/ruby/2.3.0/rdoc/generator/template/darkfish/css/images/wrench_orange.png
remote: Please check the URL references in this CSS file, particularly any
remote: relative paths which might be pointing to the wrong location.
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: http://devcenter.heroku.com/articles/django-assets
remote:
remote: ! Push rejected, failed to compile Python app
Upvotes: 2
Views: 2810
Reputation: 777
The solution was to erase this line from settings/staging.py
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
And change the wsgi.py like this:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proyecto_www.settings.staging")
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
Th dj_static library comes either with django-toolbelt or dj-static
Upvotes: 2
Reputation: 3292
This looks wrong:
STATICFILES_DIRS=(BASE_DIR,'static',)
I think you probably want something like this:
STATICFILES_DIRS=(BASE_DIR.child('static'),)
The important part of the error message you are getting is here:
The CSS file 'tmp/cache/tmp_app_dir/vendor/ruby-2.3.0/lib/ruby/2.3.0/rdoc/generator/template/darkfish/css/rdoc.css' references a file which could not be found:
tmp/cache/tmp_app_dir/vendor/ruby-2.3.0/lib/ruby/2.3.0/rdoc/generator/template/darkfish/css/images/wrench_orange.png
I don't think that file is part of your static assets, but it's getting included because your STATICFILES_DIRS
setting is wrong.
Upvotes: 0