导入Django Project的设置

时间:2014-05-24 21:54:24

标签: python mysql django path sys

通过Django教程后,我试图用MYSQL而不是SQLite开始我自己的项目。我也改变了我的项目结构,我相信这是我遇到与导入冲突的地方。

目前的项目结构

moerepo
   moesite
        manage.py
        moesite
            __init__.py
            urls.py
            wsgi.py
            settings
                base.py
                __init__.py
                local.py
                staging.py
                test.py
                production.py

我目前的最终目标是让我的项目在本地配置一个MYSQL数据库。但是,我遇到了导入基本设置以运行syncdb命令的问题。

当我运行python manage.py syncdb --settings = settings.base时...我收到以下错误。

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/alpha/django-trunk/django/core/management/__init__.py", line 427, in    execute_from_command_line
utility.execute()
File "/home/alpha/django-trunk/django/core/management/__init__.py", line 386, in execute
settings.INSTALLED_APPS
File "/home/alpha/django-trunk/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "/home/alpha/django-trunk/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/home/alpha/django-trunk/django/conf/__init__.py", line 98, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'settings.base' (Is it on sys.path? Is there an    import error in the settings file?): No module named settings.base

我的sys路径在

之下
/home/alpha/django-trunk
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/PIL
/usr/lib/python2.7/dist-packages/gst-0.10
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/pymodules/python2.7
/usr/lib/python2.7/dist-packages/ubuntu-sso-client
/usr/lib/python2.7/dist-packages/ubuntuone-client
/usr/lib/python2.7/dist-packages/ubuntuone-control-panel
/usr/lib/python2.7/dist-packages/ubuntuone-couch
/usr/lib/python2.7/dist-packages/ubuntuone-installer
/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol

显然需要的是什么不是,但我在base.py

中附加了相应的目录。
"""Path Configuration"""
DJANGO_ROOT = dirname(dirname(abspath(__file__)))
"""Site Name"""
SITE_NAME = basename(DJANGO_ROOT)

"""Abs filesystem path to the top-level project folder."""
SITE_ROOT = dirname(DJANGO_ROOT)

"""Absolute filesystem path to the secret file which holds the SECRET_KEY. Will be
auto generated the first time this file is interpreted"""
SECRET_FILE = normpath(join(SITE_ROOT, 'deploy', 'SECRET'))

"""Add all necessary filesystem paths to our system path so that we can use
python import statements"""
sys.path.append(SITE_ROOT)
sys.path.append(normpath(join(DJANGO_ROOT, 'apps')))
sys.path.append(normpath(join(DJANGO_ROOT, 'libs')))

任何指导都将非常感谢。如果我需要提供更具体的信息或者有无关的信息,请告诉我,以便我可以在此处提供所有相关信息。

1 个答案:

答案 0 :(得分:1)

尝试

--settings=moesite.settings.base