What's a settings file?
A settings file is just a Python module with module-level variables. Here are a couple of example settings:
ALLOWED_HOSTS = ['www.example.com'] DEBUG = False DEFAULT_FROM_EMAIL = '[email protected]'
Note
If you set DEBUG
to False
, you also need to properly set the ALLOWED_HOSTS
setting.
Because a settings file is a Python module, the following apply:
- It doesn't allow for Python syntax errors
- It can assign settings dynamically using normal Python syntax, for example:
MY_SETTING = [str(i) for i in range(30)]
- It can import values from other settings files
Default settings
A Django settings file doesn't have to define any settings if it doesn't need to. Each setting has a sensible default value. These defaults live in the module django/conf/global_settings.py
. Here's the algorithm Django uses in compiling settings:
- Load settings from
global_settings.py
- Load settings from the specified settings file, overriding the global settings as necessary
Note that a settings file should not import from global_settings
, because that's redundant.
Seeing which settings you've changed
There's an easy way to view which of your settings deviate from the default settings. The command python manage.py diffsettings
displays differences between the current settings file and Django's default settings. For more, see the diffsettings
documentation.