Projects, apps and manage.py

Django · Essentials · 12 min

Django's project/app structure and manage.py commands are the frame every other feature lives in.

Django separates a project (the whole site: settings, root URLs, deployment entry points) from apps (self-contained features such as blog or accounts, each with models, views, templates and migrations).

python -m pip install django
django-admin startproject mysite .
python manage.py startapp blog
python manage.py runserver

The trailing . puts manage.py in the current directory. The project package mysite/ contains:

  • settings.py: configuration, including INSTALLED_APPS and DATABASES (SQLite by default)
  • urls.py: the root URL configuration
  • wsgi.py and asgi.py: entry points for production servers

startapp blog creates models.py, views.py, admin.py, apps.py, tests.py and a migrations/ package. Django ignores the app until you add "blog" to INSTALLED_APPS; forgetting this is the classic reason models or templates are "not found".

manage.py is a wrapper around django-admin that sets DJANGO_SETTINGS_MODULE for your project. You'll use it constantly: runserver, makemigrations, migrate, createsuperuser, shell (which auto-imports your models since Django 5.2), test and check.

runserver reloads on code changes and serves on http://127.0.0.1:8000/. Like Flask's, it is for development only. Django 6.0 requires Python 3.12 or newer.

Design apps around one responsibility each; small focused apps are easier to test and reuse than one giant app.

Example

# terminal
python -m venv .venv && source .venv/bin/activate
python -m pip install "django~=6.0"
django-admin startproject mysite .
python manage.py startapp blog

# mysite/settings.py  (excerpt)
INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "blog",                       # your app must be listed here
]

# back in the terminal
python manage.py migrate          # create tables for the built-in apps
python manage.py runserver        # http://127.0.0.1:8000/

Remember

  • A project holds settings and root URLs; apps hold features
  • Add every app to INSTALLED_APPS
  • manage.py runs commands with your project's settings

Watch out for

  • Creating an app but forgetting to add it to INSTALLED_APPS.

Check yourself

  1. You created models in a new app but makemigrations says "No changes detected". What is the most likely cause?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.djangoproject.com/en/6.0/intro/tutorial01/