From Django - Difference between import django.conf.settings and import settings, I understand the accepted way to import the settings file:
from django.conf import settings
I've also read Good or bad practice in Python: import in the middle of a file. One of the answers there takes you to http://mail.python.org/pipermail/python-list/2001-July/699176.html, where points #2 and #4 are relevant to my question.
Let's say I have a huge settings.py and throughout my Django code, I only need to use a "lowly" constant like MEDIA_ROOT in one rarely-called method. So, it seems incredibly wasteful to import the entire settings.py:
from django.conf import settings
...
def foo():
my_media_root = settings.MEDIA_ROOT
when I can just import the one needed constant:
from settings import MEDIA_ROOT
...
def foo():
my_media_root = MEDIA_ROOT
and therefore avoid importing the huge settings.py, especially since it may never even be used, if my_media_root is used in only one out of many methods in that file. Of course, this is bad practice, but the "good practice version" of this doesn't work:
from django.conf.settings import MEDIA_ROOT
...
def foo():
my_media_root = MEDIA_ROOT
as, by design, it causes the expected ImportError: No module named settings
exception.
So, my question is, what is the proper way to import just one constant from a large settings.py? Thanks in advance.