Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of adding to INSTALLED_APPS in Django?

Tags:

python

django

Most documentation simply tells you to add the name of each of your apps to the INSTALLED_APPS array in your Django project's settings. What is the benefit/purpose of this? What different functionality will I get if I create 2 apps, but only include the name of one in my INSTALLED_APPS array?

like image 812
XLTChiva Avatar asked Dec 06 '17 22:12

XLTChiva


People also ask

Does order of INSTALLED_APPS matter Django?

The order of INSTALLED_APPS is significant! Django applies the following algorithm for discovering translations: The directories listed in LOCALE_PATHS have the highest precedence, with the ones appearing first having higher precedence than the ones appearing later.

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.

What is the purpose of settings py?

settings.py is a core file in Django projects. It holds all the configuration values that your web app needs to work; database settings, logging configuration, where to find static files, API keys if you work with external APIs, and a bunch of other stuff.


1 Answers

Django uses INSTALLED_APPS as a list of all of the places to look for models, management commands, tests, and other utilities.

If you made two apps (say myapp and myuninstalledapp), but only one was listed in INSTALLED_APPS, you'd notice the following behavior:

  1. The models contained in myuninstalledapp/models.py would never trigger migration changes (or generate initial migrations). You wouldn't be able to interact with them on the database level either because their tables will have never been created.
  2. Static files listed within myapp/static/ would be discovered as part of collectstatic or the test server's staticfiles serving, but myuninstalledapp/static files wouldn't be.
  3. Tests within myapp/tests.py would run but myuninstalledapp/tests.py wouldn't.
  4. Management commands listed in myuninstalledapp/management/commands/ wouldn't be discovered.

So really, you're welcome to have folders within your Django project that aren't installed apps (you can even create them with python manage.py startapp) but just know that certain auto-discovery Django utilities won't work for that application.

like image 76
Robert Townley Avatar answered Oct 19 '22 20:10

Robert Townley