Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full config path vs app name in Django INSTALLED_APPS

Tags:

django

In the Django documentation, a line reads:

New applications should avoid default_app_config. Instead they should require the dotted path to the appropriate AppConfig subclass to be configured explicitly in INSTALLED_APPS.

This suggests I should require users of my app (let's call it sports) to use the following string in their INSTALLED_APPS list:

"sports.apps.SportsConfig"

However, all of the Django apps I use (django-rest-framework, django-cors-headers, django-celery-results) use default_app_config and only require me to specify the first part of the string (in my case "sports").

So how should I write my app? (1) Follow the advice in the docs and force users to write the entire string "sports.apps.SportsConfig" or (2) Follow what all of the other apps in the Django universe are doing and allow users to write only the first part of the string "sports".

like image 244
Johnny Metz Avatar asked Mar 20 '20 06:03

Johnny Metz


People also ask

What is the difference between a project and an app in Django explain in detail?

The difference between a project and app is, a project is a collection of configuration files and apps whereas the app is a web application which is written to perform business logic.

What is app config in Django?

The AppConfig class used to configure the application has a path class attribute, which is the absolute directory path Django will use as the single base path for the application.

How do I name my Django app?

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged. So, 1 and 3 are both valid, but 3 would be the recommended approach.

Where is INSTALLED_APPS in Django?

While you're editing mysite/settings.py , set TIME_ZONE to your time zone. Also, note the INSTALLED_APPS setting at the top of the file. That holds the names of all Django applications that are activated in this Django instance.


1 Answers

I think it completely depends if you want to override custom default values of Class AppConfig for your app.

My Opinion: It's better to create CustomAppConfig (for eg. sports.apps.SportsConfig) by inheriting from Class AppConfig only for apps you create in your Django projects. Because you can tune different parameters like name, label, a verbose_name for admin panel.

like image 192
nishit chittora Avatar answered Oct 18 '22 00:10

nishit chittora