7

I've successfully deployed Django with Whitenoise on Cloudfoundry except for the compression. If I set on my settings.py to enable compression:

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

I get a 500 error and nothing on my cf logs. Please not that I don't have SSH access nor/heroku as this is running on Predix.

My settings.py:

STATIC_URL = "/media/"
STATIC_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'itcave/media'),
]

MIDDLEWARE_CLASSES = [
    '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.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

wsgi.py:

from whitenoise.django import DjangoWhiteNoise
from django.core.wsgi import get_wsgi_application
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "itcave.settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

Please also note that all my static files are stored within a media folder at the same level as my settings.py file.

Adding web: python itcave/manage.py collectstatic --noinput on a line before my run command in Procfile didn't work. ALLOWED_HOSTS is correct because when DEBUG = True everything runs fine.

Leonardo Pessoa
  • 248
  • 4
  • 16
  • Have you changed any logging settings? Can you configure the settings to email you when a server error occurs? Without any error messages or logs it'll will be difficult to debug. – A. J. Parr May 17 '17 at 13:40
  • What type of logging would you suggest? And where? – Leonardo Pessoa May 17 '17 at 22:19
  • You can define a list of admin emails to receive 500 server errors. https://docs.djangoproject.com/en/1.11/ref/settings/#admins I would presume you haven't changed the logging much, but here is a link to the documentation on logging in django. https://docs.djangoproject.com/en/1.11/topics/logging/ You could change the logging configuration to log to a file, the console, and email yourself. – A. J. Parr May 17 '17 at 23:57
  • 1
    When `DEBUG=True`, there's no need in `ALLOWED_HOSTS`, fyi. In terms of your issue, it could be helpful to know what exactly caused the app to crash. A good idea would be to set up an error tracking app, like Rollbar (saas) or Logstash (self-hosted), so that you get more insights. So, waiting for more info :) – Kostas Livieratos May 21 '17 at 18:12
  • I did. I have Kibana monitoring my logs and the only error I get is a HTTP 500. – Leonardo Pessoa May 25 '17 at 23:43
  • was so excited when I saw this question cuz it is exactly my situation, but so sad when I saw it was unanswered. +1 to the question at least. – pooley1994 Jun 17 '20 at 16:43

0 Answers0