Herman Schaaf
Herman Schaaf

Reputation: 48435

Importing settings files from settings.py gives ImportException 'DJANGO_SETTINGS_MODULE is undefined'

I'm trying to create different settings files for my development and production servers. So, in settings.py I call:

try:
    from localsettings import *
except ImportError, e:  
    print "import error", e
    pass

Then, in localsettings.py, I set the variables. However, this results in an ImportError when I run syncdb with message:

Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

I can't say that I understand what the problem is - if I move the exact same settings back to the original settings.py file, everything works fine. Can anyone please tell me what obvious thing I'm doing wrong?

Upvotes: 2

Views: 399

Answers (1)

PeanutButterJelly
PeanutButterJelly

Reputation: 1017

Make sure you're not importing something strange. I remember one time, I had the following statement:

import django.contrib.auth.backends

for use in an AUTHENTICATION_BACKENDS variable. But since that import seems to require a completely loaded settings file, it failed and I received a similar error message.

Upvotes: 2

Related Questions