pythondjangodjango-settings

Django: INSTALLED_APPS is ".apps.AppConfig" redundant?


I didn't see an answered version of this question, and this has really been bothering me because I've seen both be used.

In this example "myapp" is the created app.

I keep seeing users setup their apps inside of the INSTALLED_APPS list like this:

INSTALLED_APPS = [
    'myapp',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

instead of

INSTALLED_APPS = [
    'myapp.apps.MyappConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

So I have 2 questions

  1. Is adding the "apps.MyappConfig" after "myapp" redundant?
  2. If there is some importance to it, what is it?

Solution

    1. Is adding the "apps.MyappConfig" after "myapp" redundant?

    Often yes, but not always. If you do not specify the AppConfig in the INSTALLED_APP yourself, then Django will look for the default_app_config variable in the module, as is specified in the documentation:

    When INSTALLED_APPS contains the dotted path to an application module, Django checks for a default_app_config variable in that module.

    For example in the django.contrib.sessions module [GitHub], we see:

    default_app_config = 'django.contrib.sessions.apps.SessionsConfig'

    It is however possible to define multiple AppConfigs in a module, that each slighly alter the behavior of the application. See next section:

    1. If there is some importance to it, what is it?

    An AppConfig [Django-doc] is a class in your application that contains meta-data about the application. It contains for example the name of the app, the label, the path, et. Furthermore you can override methods like .ready() [Django-doc]. This method will be called if the models are loaded, and is often used to do some administrative tasks, or load signals when Django starts.

    We can make multiple AppConfigs, for example one for development, one for production, and one for testing. But that does not happen that often.