Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - 'myapp' vs 'myapp.apps.myappConfig' in settings.py Installed Apps

I know this might sound stupid but I was just wondering what's the difference if I just type 'myapp' instead of 'myapp.apps.myappConfig' in my Installed Apps list. Is it something related to models or what?

Regards

like image 521
notVansh Avatar asked Jul 09 '20 13:07

notVansh


1 Answers

If you use myapp.apps.myappConfig, then you are explicitly telling Django to use that app config class.

Changing the app config class lets you change the behaviour of the application, for example, when you use the admin app, you can use django.contrib.admin.apps.AdminConfig which autodiscovers apps, or django.contrib.admin.apps.SimpleAdminConfig, which does not.

If you just use myapp, then Django will try to use default_app_config. If that isn't set, then it will use the default AppConfig.

A lot of the time, there isn't any customisation in myappConfig, or default_app_config is set, so you'll get the same behaviour whichever style you use in INSTALLED_APPS.

Ever since AppConfig was added in Django 1.7, the recommendation has been to use ``myapp.apps.myappConfigbecause it's explicit, and avoid usingdefault_app_config`.

However, in practice, it seems that users have preferred the simplicity of using myapp. Therefore, there's an open pull request which will remove default_app_config, and automatically select the app config class when there is only one.

like image 113
Alasdair Avatar answered Oct 04 '22 16:10

Alasdair