djangoherokudjango-staticfileswhitenoise

How to setup wsgi.py file in Django for WhiteNoise 5.1.0?


I use Heroku and i have a problem with static files - they are creating in STATIC_ROOT. I've got that i need to setup wsgi.py file for WhiteNoise. I tried some different ways which i found to setup it but i every time get fail. Here is my code:

/wsgi.py

import os
from django.conf import settings
from django.core.wsgi import get_wsgi_application

from whitenoise import WhiteNoise

application = get_wsgi_application()
application = WhiteNoise(application, root=settings.STATIC_ROOT)

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api_obs.settings')

With this here is the last error message in errors thread:

gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.'

What the right way to setup it? My settings.py file is right here is my previous question with them. I only haven't declared STATICFILES_DIRS but it's not required right?


Solution

  • You don't need to edit wsgi.py, that hasn't been supported since WhiteNoise 4.0 which was released two years ago.

    You just need to edit your MIDDLEWARE setting, see: http://whitenoise.evans.io/en/stable/index.html#quickstart-for-django-apps