I'm reading up that most people do from django.conf import settings
but I don't undertstand the difference to simply doing import settings
in a django project file. Can anyone explain the difference?

- 2,523
- 3
- 21
- 24
-
django.conf settings are django default or "global" settings which you may override with your own project based settings. – Jingo Nov 14 '13 at 11:16
-
13NEVER EVER use the second form. The first one is the only correct one. – bruno desthuilliers Nov 14 '13 at 12:03
-
4But why never use the second one? – tzenderman Nov 14 '13 at 13:42
-
2possible duplicate of [Django Importing Settings File](http://stackoverflow.com/questions/8780756/django-importing-settings-file) – Anto Apr 09 '14 at 22:21
2 Answers
import settings
will import the first python module named settings.py
found in sys.path
. Usually (in default django setups) it allows access only to your site defined settings file, which overwrites django default settings (django.conf.global_settings
).
So, if you try to access a valid django setting not specified in your settings file you will get an error.
django.conf.settings
is not a file but an object (see source) making an abstraction of the concepts, default settings and your site-specific settings. Django also does other checks when you use from django.conf import settings
.
You can also find it in the django docs.

- 20,030
- 7
- 43
- 238

- 5,706
- 8
- 44
- 63
-
7`import settings` will import the first python module named `settings.py` found in `sys.path`. This may not be the "site defined settings file", which is looked up in the environment variable "DJANGO_SETTINGS_MODULE" and can be just any python package or module. – bruno desthuilliers Nov 14 '13 at 12:02
-
@brunodesthuilliers thanks you. I update my answer taking aware of your correction. – juliocesar Nov 14 '13 at 12:16
-
1Keeping `settings.py` next to `manage.py` (in the project root) is a default Django setup? O.o I believe the default one is to have it at `
/settings.py`. At least that's where `django-admin startproject` puts it. – x-yuri Jan 07 '21 at 10:12
from django.conf import settings
is better option.
I use different settings files for the same django project (one for "live", one for "dev"), the first one will select the one being executed.

- 3,937
- 1
- 24
- 33

- 782
- 5
- 17