配置不正确:请求的设置为INSTALLED_APPS,但未配置设置 [英] ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured

查看:2698
本文介绍了配置不正确:请求的设置为INSTALLED_APPS,但未配置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使MongoDB和Django以我希望的方式彼此兼容. 这是我尝试从rest_framework_mongoengine导入视图集时遇到的错误.

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.

整个错误如下:

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.

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.

找不到settings.py还是什么?如果是这样,我不知道为什么!也就是说,为什么这个问题没有出现在其他模块上?

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?

这是我的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',
]

推荐答案

最常见的原因是您只运行python而不是使用python manage.py shell,这意味着您需要手动设置DJANGO_SETTINGS_MODULE环境变量,以便Django知道在哪里可以找到您的设置(manage.py shell会自动为您完成设置).

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).

这篇关于配置不正确:请求的设置为INSTALLED_APPS,但未配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆