Reputation: 2257
I was looking at the Django source code on GitHub (specifically the django.conf module) and I understand from this post that you should never import the global_settings module itself, but rather just:
from django.conf import settings
So I know this works and all that, but as someone who is getting used to looking at the source code to understand how the some of the "under the hood" stuff works for Django, I'd like to get more detail on how I can import "settings" when there is no settings.py in the django/conf directory.
I'm assuming that this is a django built-in where you "from django.conf import settings" and it's intercepted by the django engine and the correct settings module is built/etc. then passed along. Is this the case, or is there something else happening here that I'm missing?
Upvotes: 1
Views: 2395
Reputation: 410592
from django.conf import settings
says "look for the django.conf
module and import a variable called settings
from it".
django.conf
is a package, so the source code django.conf
module can be found in the file django/conf/__init__.py
. Looking at that, there is a variable at the end called settings
which is an instance of LazySettings
. The source code for LazySettings
can be found near the beginning of the file.
Upvotes: 7