What is installed_apps in Django: Explanation and Usage
INSTALLED_APPS is a list in the settings file that tells Django which apps are active for your project. It helps Django know where to find models, views, templates, and other app components to include in your project.How It Works
Think of INSTALLED_APPS as a guest list for a party. Django only invites the apps listed here to participate in your project. Each app can add features like database models, admin pages, or templates. When Django starts, it looks at this list to load and connect these apps properly.
This list is in your settings.py file and usually includes both your own apps and built-in Django apps. By listing an app here, Django knows to check it for database tables, static files, and other resources it needs to run your site.
Example
This example shows a simple INSTALLED_APPS list in a Django settings file. It includes default Django apps and a custom app called blog.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog', # Custom app
]When to Use
You use INSTALLED_APPS whenever you add a new app to your Django project. This includes apps you create yourself or third-party apps you install. Adding an app here lets Django include its features, like database models or admin interfaces.
For example, if you add a blog feature, you create a blog app and add it to INSTALLED_APPS. Django then knows to create database tables for the blog and show its admin pages.
Key Points
- Lists active apps: Only apps in
INSTALLED_APPSare used by Django. - Includes built-in and custom apps: Both Django’s default apps and your own apps go here.
- Controls database and admin setup: Django uses this list to create tables and admin pages.
- Must update when adding apps: Always add new apps here to activate them.
Key Takeaways
INSTALLED_APPS tells Django which apps to include in your project.INSTALLED_APPS.