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?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
import settings
will import the first python module namedsettings.py
found insys.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 a class making an abstraction of the concepts, default settings and your site-specific settings. Django also does other checks when you usefrom django.conf import settings
.You can also find it in the django docs.
Hope this helps.
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.