简体   繁体   中英

Importing settings in Django

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM