heroku-python / dj-static

DEPRECATED - use WhiteNoise instead!
http://kennethreitz.org/introducing-dj-static/
BSD 2-Clause "Simplified" License
511 stars 74 forks source link

Error when deploying to Heroku #28

Closed jcpmmx closed 9 years ago

jcpmmx commented 10 years ago

I was having this error when trying to deploy a Django app to Heroku (following their tutorial). This also happens when running foreman start locally.

ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured.
You must either define the environment variable DJANGO_SETTINGS_MODULE or call
settings.configure() before accessing settings.

The solution? Setting the DJANGO_SETTINGS_MODULE before importing and calling Cling.

import os
from django.core.wsgi import get_wsgi_application

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

from dj_static import Cling
application = Cling(get_wsgi_application())
kennethlove commented 10 years ago

Yeah, that worked for me too. That's a really picky bug.

jcpmmx commented 10 years ago

@kennethlove Glad it helped you.

ckcollab commented 10 years ago

Fixed for me as well!

flevour commented 9 years ago

This can be closed.

ryneeverett commented 9 years ago

Why was this closed? Shouldn't it at least be documented in the README?

kennethreitz commented 8 years ago

Why would DJANGO_SETTINGS_MODULE not be set? How are you launching Django?

jcpmmx commented 8 years ago

Not sure right now TBH. But I remember debugging that and getting the error, and solving it by having DJANGO_SETTINGS_MODULE move up before Cling.

ryneeverett commented 8 years ago

Why would DJANGO_SETTINGS_MODULE not be set?

@kennethreitz It wouldn't be set unless you set the environmental variable. Often this is unnecessary which is why the default wsgi.py created by startproject sets a default:

"""
WSGI config for mysite project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()