Is there any difference between django.conf.settings and import settings?

PythonDjangoDjango Settings

Python Problem Overview


What is the basic difference between the following import statements in a Django app?

import settings

and

from django.conf import settings

Python Solutions


Solution 1 - Python

import settings

Will import settings(.py) module of your Django project (if you are writing this code from the "root" package of your application, of course)

from django.conf import settings

Will import settings object from django.conf package (Django's provided files). This is important, because

> [..] note that your code should not import from either global_settings or your own settings file. django.conf.settings abstracts the concepts of default settings and site-specific settings; it presents a single interface. It also decouples the code that uses settings from the location of your settings.

UPDATE: if you want to define some own settings, see this part of the documentation

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOzgur VatanseverView Question on Stackoverflow
Solution 1 - Pythonuser237076View Answer on Stackoverflow