What's the difference between `from django.conf import settings` and `import settings` in a Django project

五迷三道 提交于 2019-12-02 17:49:35
juliocesar

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 a class 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.

Hope this helps.

mansuetus

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!