Reputation: 3725
It's recommended to import the settings module as such:
from django.conf import settings
My settings
module structure is:
├── settings
│ ├── base.py
│ ├── dev.py
│ └── prod.py
I have a variable, amb
, defined in base.py
, which both dev.py
and prod.py
import from:
from .base import *
So how come when I do this in a test file:
import django
sys.path.append("/path/to/project/")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "root_folder.settings.dev")
# even when the above line is omitted
django.setup()
from django.conf import settings
print(settings.amb) # or settings.AMB
I get this error?
AttributeError: 'Settings' object has no attribute 'amb'
Same goes if I try settings.base.amb
Upvotes: 0
Views: 513
Reputation: 32244
django.conf.settings
will only return UPPERCASE variables from your settings module. It’s not that lowercase variables are imported as UPPERCASE, they aren’t imported at all.
You can try renaming it to AMB
.
Upvotes: 2