Reputation:
I was reading this article here about django settings
I understand "that django.conf.settings isn’t a module – it’s an object." That's why I can't import variables. I only need the statement CURRENCIES in my settings.
Is the right approach to do from django.conf import settings
and then var = settings.CURRENCIES
or can I do from [projectname].settings import CURRENCIES
Both is working for me. But I wonder if there is a recommended approach.
Upvotes: 0
Views: 1612
Reputation: 47364
This method from django.conf import settings
is preferable. You may have different setting files for different environments, for instance test_settings.py
, dev_settings.py
and prod_settings.py
. With from django.conf import settings
your code will automatically give you settings using by your project at the moment.
Also second method will not provide you access to the default settings not defined in setting file.
Quote from django docs:
Also 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.
Upvotes: 2