Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is from Django Conf import settings?

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.

Where is Django Conf settings?

Default settings These defaults live in the module django/conf/global_settings.py .

What is the purpose of settings py in Django?

settings.py is a core file in Django projects. It holds all the configuration values that your web app needs to work; database settings, logging configuration, where to find static files, API keys if you work with external APIs, and a bunch of other stuff.

How do I import python settings?

In your python settings file, you have to import our LazySetting class located in python_settings. Only the first time you call this property, the HeavyInitializationClass will be instantiated and the *args and **kwargs parameters will be passed. Every time you call this property the same instance will be returned.


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