Yeonho
Yeonho

Reputation: 3623

Error when using django-admin.py

Please bear with me as I'm new to Python/Django/Unix in general.
I'm learning how to use different settings.py files for local and production environments. The following is from the section on the --settings option in the official Django docs page on django-admin.py,

--settings Example usage:

django-admin.py syncdb --settings=mysite.settings

My project is structured as following:

mysite
L manage.py 
L mysite
   L __init__.py  
   L local.py
   L urls.py
   L production.py 
   L wsgi.py

However when I run the following command from the parent mysite directory,

$ django-admin.py runserver --settings=mysite.local

I get the following error:

File "/Users/testuser/.virtualenvs/djdev/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'mysite.local' (Is it on sys.path?): No module named mysite.local

From what I gathered on various articles on the web, I think I need to add my project directory path to the PYTHONPATH variable in bash profile. Is this the right way to go?

EDIT: changed the slash to dot, but same error persists.

Upvotes: 1

Views: 136

Answers (2)

Siva Arunachalam
Siva Arunachalam

Reputation: 7740

You have to replace / with .

$ django-admin.py runserver --settings=mysite.local

You can update PYTHONPATH in the manage.py too. Inside if __name__ == "__main__": add the following.

import sys
sys.path.append(additional_path)

Upvotes: 1

Demian Brecht
Demian Brecht

Reputation: 21368

the --settings flag takes a dotted Python path, not a relative path on your filesystem.

Meaning --settings=mysite/local should actually be --settings=mysite.local. If your current working directory is your project root when you run django-admin, then you shouldn't have to touch your PYTHONPATH.

Upvotes: 2

Related Questions