Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

  • Is adding the "apps.MyappConfig" after "myapp" redundant?
  • If there is some importance to it, what is it?
  • To configure an application, subclass AppConfig and put the dotted path to that subclass in INSTALLED_APPS.

    If there is no default_app_config, Django uses the base AppConfig class

    If you need to add extra app configurations (e.g. importing Signals), you can do so in your app config and would then need to include it in your INSTALLED_APPS. Otherwise, you can include only your app in the INSTALLED_APPS

    So to answer your questions:

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

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

    Yes, adding extra config

    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:

  • 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.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.