ImproperlyConfigured: Requested setting INSTALLED_

2020-06-12 04:57发布

I'm trying to make MongoDB and Django get on with each other the way I want them to. That's the error I'm getting when trying to import viewsets from rest_framework_mongoengine.

The whole error looks like this:

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

It doesn't find settings.py or what? If so I can't figure out why! Namely, say, why did this problem not appear with other modules then?

Here are my INSTALLED APPS

INSTALLED_APPS = [
    'rest_framework',
    'rest_framework_mongoengine',
    'mongoengine.django.mongo_auth',
    'rest_framework.authtoken',
    'corsheaders',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_extensions',
    'core',
    'core.essences.user',
    'core.essences.user.authentication',
    'core.essences.test_result',
]

3条回答
小情绪 Triste *
2楼-- · 2020-06-12 05:38

try this in your xx.py "from youprojectName.wsgi import *"

查看更多
淡お忘
3楼-- · 2020-06-12 05:52

Most common cause of this is that you're just running python instead of using python manage.py shell, which means you need to manually set the DJANGO_SETTINGS_MODULE environment variable so Django knows where to find your settings (manage.py shell does that for you automatically).

It's also possible (but less common) that you have something that's trying to import settings during the process of setting up your settings. To determine if that's the case, look at your settings file for any imports or function calls that might need to access settings (including code in things being imported by your settings file).

查看更多
我只想做你的唯一
4楼-- · 2020-06-12 05:53

just simply run python manage.py shell instead of running python to reach your environment shell in your project. python does not simply recognize django installed apps by default.

查看更多
登录 后发表回答