When you use Django, you have to tell it which settings you're using. Do this by using an environment variable, DJANGO_SETTINGS_MODULE
. The value of DJANGO_SETTINGS_MODULE
should be in Python path syntax, for example, mysite.settings
.
When using django-admin
, you can either set the environment variable once, or explicitly pass in the settings module each time you run the utility. Example (Unix Bash shell):
export DJANGO_SETTINGS_MODULE=mysite.settings
django-admin runserver
Example (Windows shell):
set DJANGO_SETTINGS_MODULE=mysite.settings
django-admin runserver
Use the --settings
command-line argument to specify the settings manually:
django-admin runserver --settings=mysite.settings
In your live server environment, you'll need to tell your WSGI application what settings file to use. Do that with os.environ
:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
Read Chapter 13, Deploying Django, for more information and other common elements to a Django WSGI application.