I hope this doesn't confuse you more. But I'll do my best.
Let's say you ran python manage.py startapp hello
django creates directories/files for you by default including the apps.py.
But in order to use the hello
app you have to add it in INSTALLED_APPS
project settings.
When you ran python3 manage.py runserver
it does this (in summary):
- first loads your project's settings.py
- Then goes to each of the
INSTALLED_APPS
- creates an 'app class' for each of the installed apps. It will use what's in
apps.py
by default if it exists. Otherwise, it will just load the base AppConfig.
^ That answers: The application server takes the INSTALLED_APPS and loads or generates an AppConfig object for each app
For this context: This collection of AppConfig objects are then stored in an instance of theApps class.
In my example above, it created a class helloConfig(AppConfig)
. The class helloConfig inherited from AppConfig.
If I were to create an instance it will looks like this.
myinstance = helloConfig()
myinstance #-> `collection of AppConfig objects are then stored` in the `myinstance`
Imagine Django doing that for each of the Installed app with the respect to the apps' name.
Additional side note, It's not required for the every apps to have an apps.py but AppConfig has other attributes that may be useful. If you want to utilize those attributes, django creates a class wrapper (class helloConfig) that inherits from the AppConfig.
This way you can use def ready()
which is one of the attributes in AppConfig (without editing AppConfig's ready method directly)
class HelloConfig(AppConfig):
...
def ready():
# Run this when the Hello app is ready