Why is whitenoise crashing in a default Django project on Heroku?

I'm trying to launch a new Django app, following Heroku's instructions. When I get to activating whitenoise it crashes. I haven't even written any app code yet. What's going wrong? Here's the traceback of a web worker crashing:

[2015-06-26 20:37:36 +0000] [11] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
  File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
    self.callable = self.load()
  File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
  File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
  File "/app/prompt/wsgi.py", line 4, in <module>
    from whitenoise.django import DjangoWhiteNoise
  File "/app/.heroku/python/lib/python2.7/site-packages/whitenoise/django.py", line 14, in <module>
    from django.contrib.staticfiles.storage import staticfiles_storage
  File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 12, in <module>
    from django.core.cache import (
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/cache/__init__.py", line 34, in <module>
    if DEFAULT_CACHE_ALIAS not in settings.CACHES:
  File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
  File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Note that the application worked fine, correctly serving the index page 404, until I edited the wsgi.py file as specified in https://devcenter.heroku.com/articles/django-assets


What does your wsgi.py file look like? Note that you must initialize settings before importing whitenoise, as per this issue on github. Try something like this:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "prompt.settings")

from whitenoise.django import DjangoWhiteNoise

application = DjangoWhiteNoise(get_wsgi_application())

Need Your Help

JavaScript - Sort SELECT options

javascript html select sorting

Using PHP, I scan a directory and list all of the .xml files. Each XML file contains both a "name" element and a "date" element. The "name" element for each XML file is listed as an option in the ...

ISO 8601 datetime now

java c# date datetime

I need exactly that format in java which in C# is