简体   繁体   中英

Importing settings for Django Project

After getting though the Django Tutorial, I am trying to start my own project with MYSQL instead of SQLite. I have also switched up the structure of my project, and I believe this is where I am running into conflicts with imports.

Project Structure Currently

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

My end goal currently is to have my project locally configured with a MYSQL database. However I am running into issues importing the base settings to run the syncdb command.

When I run python manage.py syncdb --settings=settings.base... I receive the error below.

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

My sys path is below

/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

Obviously what needs to be there is not, but I have appended what should be the appropriate directories with this in my 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')))

Any guidance would be most appreciated. If I need to provide more specific information or if there is irrelevant information, please let me know so I can make all information here relevant.

试试看

--settings=moesite.settings.base

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM