-1

I am deploying my Django application on Heroku. It has been deployed successfully. But static files are not loading.

I followed this link, but when Whitenoise 3.x is included, the command

python manage.py collectstatic --noinput

fails.

my Procfile:

python manage.py collectstatic --noinput
web:python manage.py runserver
web: gunicorn MovieTracker.wsgi --log-file -
heroku ps:scale web=1

I have also tried with :

heroku config:set DISABLE_COLLECTSTATIC=1

and also :

heroku config:set DISABLE_COLLECTSTATIC=0

The settings.py file is:

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tracker',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    # 'whitenoise.middleware.WhiteNoiseMiddleware',
)

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "/tracker/static")
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

with whitenoise enabled, ERROR:

Build error

Rakmo
  • 1,926
  • 3
  • 19
  • 37

2 Answers2

1

You should remove the leading slash on your STATIC_ROOT sub-path.

STATIC_ROOT = os.path.join(BASE_DIR, "tracker/static")
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • You do need to show the actual error message from collectstatic. – Daniel Roseman Sep 27 '17 at 12:48
  • There is no error in Build or in logs. Build : Successful. Logs: State changed from starting to Up. – Rakmo Sep 27 '17 at 12:48
  • collectstatic worked fine when I corrected the bug, as mentioned by you. But still static files are not loaded. – Rakmo Sep 27 '17 at 12:48
  • What should the status of this? heroku config:set DISABLE_COLLECTSTATIC=0 or 1 ? – Rakmo Sep 27 '17 at 12:49
  • And shall I include whitenoise in settings? – Rakmo Sep 27 '17 at 12:53
  • When whitenoise enabled. ERROR: 'ImproperlyConfigured: Error importing module whitenoise.middleware: "cannot import name FileResponse"' – Rakmo Sep 27 '17 at 12:57
  • Please update your question with the full traceback. – Daniel Roseman Sep 27 '17 at 13:01
  • Error importing module whitenoise.storage: "cannot import name ManifestStaticFilesStorage" – Rakmo Sep 27 '17 at 13:03
  • What does that error have to do with the previous one? Stop posting single lines in comments; post the *whole error message and traceback* as an update to the question. Also state which version of Django you are using. – Daniel Roseman Sep 27 '17 at 13:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/155425/discussion-between-omkar-deshpande-and-daniel-roseman). – Rakmo Sep 27 '17 at 13:12
0

There is version conflict between whitenoise and Django in the project. The project uses Django 1.6 whereas whitenoise version that was being used was

Whitenoise 3.x

Compatibility follows:

Django 1.6 and lower with Whitenoise 2.x

Settings are given in this link for whitenoise 2.x.

Django 1.7 and above with Whitenoise 3.x

Follow this for whitenoise 3.x.

Set the version in requirements.txt accordingly.

In the Procfile, just the following line is enough.

web: gunicorn MovieTracker.wsgi --log-file
Rakmo
  • 1,926
  • 3
  • 19
  • 37
  • 1
    Also note that support for Django 1.6 (including security fixes) ended in April 2015, so you should really upgrade your project to a newer version. – D. Evans Sep 27 '17 at 14:25