I am working on Django project that uses several dozen configuration variables specified in several "settings" files located in project's root directory:
--> myproject
------> app folders
------> ...
--- settings.py
--- settings_global.py
--- settings_production.py
--- settings_development.py
Variables from different settings_* files are then get imported in settings.py file based on certain run-time parameters (host name etc). It all works rather well, but sometimes it's still hard to locate certain variable, so I'd like re-organize settings variables and split them into several categories:
Also I'd like to move all settings files but settings.py file to settings subdirectory:
--> myproject
------> app folders
------> ...
------> settings
---------- __init__.py
---------- common.py
---------- production.py
---------- development.py
---------- apps.py
---------- ...
--- settings.py
I've created settings subdirectory (as well as empty __init__.py
file) and copied/renamed the settings files. Then I tried to import those variables in my setting.py file as following:
from settings.common import *
from settings.apps import *
However, I am getting the following error (even though ROOT_URLCONF exists in settings/common.py file):
AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
What am I doing wrong?
A Django settings file doesn't have to define any settings if it doesn't need to. Each setting has a sensible default value. These defaults live in the module django/conf/global_settings.py .
Insights about settings.py file. A Django settings file contains all the configuration of your Django Project. In this article the important points of settings.py file of Django will be discussed. A settings file is just a Python module with module-level variables.
Creating Environment Variables Create a . env file in the same directory where settings.py resides and add the following key-value pair inside the file. We will use django-environ for managing environment variables inside our project. So let's install the package.
I think there's a name collision between your settings.py module and the settings package, try renaming the package to something else
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With