Reputation: 2694
I have recently started working with a settings directory as described in the Two Scoops of Django book. It contains the following files
local.py
staging.py
production.py
test.py
__init__.py
To be able to use the different setting files on the server I have adapted my django.fcgi script to import the settings module. It works very smoothly.
How do I do the same on my local machine on which I use runserver, however? I have set the DJANGO_SETTINGS_MODULE and I have adapted the manage.py
file to
#!/usr/bin/env python
from django.core.management import execute_manager
import imp
import sys
sys.path.insert(0, '/home/user/don.joey/projects/a_project/a_project_site/settings')
import settings
try:
imp.find_module('settings') # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)
It works fine.
How can I make django-admin.py
find these settings? I do not want to manually edit django-admin.py because it is part of my virtualenv and it will does thus regularly be updated.
I have set the following: export DJANGO_SETTINGS_MODULE=settings.local
.
Upvotes: 1
Views: 2453
Reputation: 4584
You need to set two things
DJANGO_SETTINGS_MODULE
andPYTHONPATH
so that the settings module can be foundThe way Two Scoops of Django suggests setting up a project named blah
you would have the following directory structure:
- blah_project/
- blah/
- manage.py
- blah/
- ...
- settings/
- __init__.py
- local.py
- production.py
- ...
Run the following (assuming a bash
environment):
export DJANGO_SETTINGS_MODULE=blah.settings.local
export PYTHONPATH=/full/path/to/blah_project/blah
As long as django-admin.py
is on your path (and it should be if django
is installed and activated within your venv
), you should be able to run:
django-admin.py runserver
Upvotes: 2