What Is a Django App?
A Django app is one part of a project. Each app holds the code for one job, like a blog or a shop.
List the apps
This list lives in settings.py. Each line names one app of the project.
INSTALLED_APPS = [
"django.contrib.contenttypes",
"django.contrib.auth",
"blog",
]One app, one job
The blog app holds a view for posts. The shop app would hold the views for a shop.
from django.http import HttpResponse
def post_list(request):
return HttpResponse("All posts")List the installed apps
The app registry knows every installed app. This print shows their names in order.
from django.apps import apps
print([config.name for config in apps.get_app_configs()])Example
import django
from django.conf import settings
settings.configure(
DEBUG=True,
SECRET_KEY="key",
ROOT_URLCONF=__name__,
ALLOWED_HOSTS=["*"],
INSTALLED_APPS=["django.contrib.contenttypes", "django.contrib.auth"],
)
django.setup()
from django.apps import apps
print([config.name for config in apps.get_app_configs()])
print(apps.get_app_config("contenttypes").name)
Key points
- An app is a Python package with its own views and models.
- INSTALLED_APPS lists the apps of a project.
- Django ships apps like contenttypes and auth.
- One project holds many apps.
In this example, the setup lines configure Django. The settings list two apps, contenttypes and auth. The app registry is the record of installed apps. The first print shows their names in order. The second print asks for the contenttypes app by name and prints its name.
Note
An app alone serves nothing until the project lists it.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What is a Django app?