ImportError:没有名为' app.settings.ci&#39 ;;的模块' app.settings'不是一个包

时间:2018-01-31 12:26:13

标签: python django

我有一个错误:

ImportError: No module named 'app.settings.ci'; 'app.settings' is not a package.

我想将CircleCI 2.0安装到Django应用程序中。追溯说:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/xxx/anaconda/envs/rf/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/xxx/anaconda/envs/rf/lib/python3.5/site-packages/django/core/management/__init__.py", line 317, in execute
    settings.INSTALLED_APPS
  File "/Users/xxx/anaconda/envs/rf/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/Users/xxx/anaconda/envs/rf/lib/python3.5/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/xxx/anaconda/envs/rf/lib/python3.5/site-packages/django/conf/__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/xxx/anaconda/envs/rf/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ImportError: No module named 'analytics_api.settings.ci'; 'analytics_api.settings' is not a package

发生错误时,我运行命令python manage.py makemigrations --settings app.settings.ci。我认为这个命令是安装CircleCI 2.0所必需的,但是它错了吗?我怎样才能解决这个问题?我的代码出了什么问题?

在settings.py中我写了

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app',
    'data',
    'user',
]

1 个答案:

答案 0 :(得分:1)

要拥有多个设置文件,您需要创建一个Python模块并使用它。

/app
|-- settings
|   |-- __init__.py
|   |-- base.py <--- the current setting.py file
|   |-- ci.py

ci.py

from .base import *

# override settings here

注意:

您可以将环境变量DJANGO_SETTINGS_MODULE设置为使用默认设置。