ImportError:无法导入设置'testapp.settings.local'

时间:2015-02-28 10:39:13

标签: python django

我在我的ubuntu服务器上安装了django, 我尝试运行以下命令:

./ manage.py syncdb --noinput

/manage.py runserver --settings=testapp.settings.local 

或通过manage.py的任何命令, 我收到以下错误:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/cchq/.virtualenvs/commcare-hq/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/cchq/.virtualenvs/commcare-hq/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "/home/cchq/.virtualenvs/commcare-hq/local/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
    self._setup(name)
  File "/home/cchq/.virtualenvs/commcare-hq/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/cchq/.virtualenvs/commcare-hq/local/lib/python2.7/site-packages/django/conf/__init__.py", line 98, in __init__
    % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'testapp.settings.local' (Is it on sys.path? Is there an import error in the settings file?): No module named testapp.settings.local

以下是我的manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

我该如何解决这个问题? 请指教?

1 个答案:

答案 0 :(得分:0)

您应该创建包含至少两个文件的testapp/settings目录:local.py包含您的设置和__init__.py

不要忘记删除testapp/settings.py(如果存在)(其内容应移至testapp/settings目录)。