XLTChiva
XLTChiva

Reputation: 375

What is the purpose of adding to INSTALLED_APPS in 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?

Upvotes: 24

Views: 9051

Answers (1)

Robert Townley
Robert Townley

Reputation: 3564

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.

Upvotes: 34

Related Questions