← Back to Django, page 1

django-0002 · Easy fresher

What is the difference between a Django project and a Django app?

A project is the whole website: settings, root URLs and the WSGI/ASGI entry points. An app is a reusable package that does one job, such as attendance or library, with its own models, views and migrations. A project contains many apps, listed in INSTALLED_APPS.

Full answer

A project is the container for one website. django-admin startproject college creates it, with settings.py (database, installed apps, middleware), the root urls.py, and wsgi.py / asgi.py, which web servers use to load the app.

An app is a Python package that handles one area of the business. python manage.py startapp attendance creates models.py, views.py, admin.py, apps.py, tests.py and a migrations/ folder. A college site might have students, attendance and library apps.

An app only becomes active when its name (or its AppConfig path) is added to INSTALLED_APPS. Django then:

  • finds its models and creates migrations for them,
  • loads its admin.py,
  • looks for templates in its templates/ folder and static files in static/,
  • runs its AppConfig.ready() method at startup, which is where signal handlers are usually connected.

Django itself is built from apps: django.contrib.auth, django.contrib.admin, django.contrib.sessions.

How big should an app be? A good test is whether you can describe it in one short sentence without "and". "Tracks book loans" is one app. "Handles books and fees and hostel rooms" is probably three. Apps that are too large become hard to test; apps that are too tiny create many cross-imports. Avoid circular dependencies, where app A imports models from app B and B imports from A.

python
import sys
import types

import django
from django.conf import settings

# Register a tiny in-memory "school" app so this example runs as one file
sys.modules["school"] = types.ModuleType("school")
sys.modules["school"].__file__ = __file__

settings.configure(
    SECRET_KEY="demo-only-key-not-for-production",
    ALLOWED_HOSTS=["testserver"],  # the host name used by Django's test client
    INSTALLED_APPS=["django.contrib.contenttypes", "django.contrib.auth", "django.contrib.sessions", "school"],
    DATABASES={"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}},
)
django.setup()

from django.apps import apps

# Every entry in INSTALLED_APPS becomes an AppConfig
for config in apps.get_app_configs():
    print(config.label, "->", config.name)

# Models are registered per app
print([m.__name__ for m in apps.get_app_config("auth").get_models()])

Standalone script. The first lines register a tiny in-memory app called school and an in-memory SQLite database so the file runs with `python file.py`. In a real project the settings live in settings.py and models live in an app's models.py. Output (ran twice with identical results; Python 3.13.5, Django 5.2.20, djangorestframework 3.18.3): contenttypes -> django.contrib.contenttypes auth -> django.contrib.auth sessions -> django.contrib.sessions school -> school ['Permission', 'Group', 'User']

Key points

  • Project = settings + root URLs + server entry points
  • App = one feature area with models, views, migrations
  • Apps are activated through INSTALLED_APPS
  • AppConfig.ready() runs once at startup
  • Django's own features are apps too

Common mistakes

  • Putting every model into one giant app
  • Creating an app but forgetting to add it to INSTALLED_APPS, so migrations are never generated
  • Importing models at module level inside AppConfig before the registry is ready
  • Naming an app the same as an existing Python module, such as 'test' or 'email'

Follow-ups

  • How would you split an online library system into apps?
  • What does AppConfig.ready() do and what should not go in it?
  • How do you make an app reusable across two projects?

Tips

  • Show a concrete split for a real domain, it proves you have designed one
  • Mention INSTALLED_APPS and what Django discovers from it
  • Bring up circular imports as the main risk of a poor split