---
django: 6.1.3 (f16e25dcb9fe55734ba4ea2b00ac34405b7df74a)
part: The request
promise: Just import your models and go.
contents: lazy-settings, apps-registry, import-order, ready-hook, overrides
---

# Booting Django

Lazy configuration, the two-phase app registry, and why import order decides whether a project starts cleanly or crashes before the first request.

Inside a running Django view or management command, configuration and models feel as ambient as Python builtins. Any file can import `settings`, read a flag, and import any model from any app without asking who loaded them or in what order. Step outside an already-booted worker — write a standalone script, drop a model import into an app's `__init__.py`, query a table during startup, or assign directly to `settings` in a test — and the illusion breaks at once into `ImproperlyConfigured`, `AppRegistryNotReady`, `OperationalError`, or silently stale caches.

Everything that turns an ordinary Python interpreter into a booted Django process fits inside a seventeen-line function, `django.setup` (`django/__init__.py:setup`). On our modest eight-app newsroom project, running `django.setup` cold across five fresh Python processes takes a median of **`312.86 milliseconds`**. Almost nobody guesses where that third of a second actually goes.

## Where the 313 milliseconds go

```text figure=boot-budget
cold django.setup() on desk/ across 5 fresh Python subprocesses (Django 6.1.3, median 312.86 ms, least 306.46 ms)

one continuous boot, proportional to total time (0 to 312.86 ms):
  import django.urls (setup line 16)    124.78 ms   39.9%
  Settings.__init__ (desk.settings)       2.68 ms    0.9%
  configure_logging (dictConfig)         24.12 ms    7.7%
  Phase 1: AppConfig.create x 8          71.21 ms   22.8%
  Phase 2: import_models x 8             73.74 ms   23.6%
  Phase 3: AppConfig.ready x 8           14.05 ms    4.5%
  Total django.setup()                  312.86 ms
```

*A cold boot of our newsroom project measured in five fresh subprocesses (`ch02-bench`). Nearly forty percent of `django.setup` is spent importing `django.urls` on line 16 before logging or the app registry even starts; loading `"desk.settings"` itself takes less than three milliseconds.*

Look at the two ends of that bar. Parsing our settings module — copying `150` uppercase defaults from `django.conf.global_settings` and overlaying `20` explicit project settings — takes just **`2.68 milliseconds`**, less than one percent of startup. Meanwhile, a single lazy `from django.urls import set_script_prefix` inside `django.setup` pulls in Django's URL, HTTP, and internationalization modules for the first time and consumes **`124.78 milliseconds`** (`39.9%`) before a single application is discovered.

Then `Apps.populate` takes over (`django/apps/registry.py:Apps.populate`), spending `71.21 ms` discovering and constructing eight `AppConfig` objects, `73.74 ms` importing models and registering eighteen model classes (`15` explicit models plus `3` auto-created many-to-many join tables), and `14.05 ms` running every `AppConfig.ready` hook — including `AdminConfig.ready` scanning every installed app for admin registrations.

## Why boot is split into strict phases

Django pays that orchestration complexity to solve two problems that would otherwise deadlock every non-trivial project.

First, dozens of Django's own modules run `from django.conf import settings` at import time, long before a process has configured `"DJANGO_SETTINGS_MODULE"` or called `LazySettings.configure`. Django therefore ships `settings` as an unevaluated `LazyObject` shell that stays completely inert until the very first attribute read, caches resolved keys onto its instance `__dict__`, and still pays a measurable pure-Python `__getattribute__` tax on every lookup (`236.4 ns` versus `17.0 ns` for a plain object attribute).

Second, Python executes a model's `ModelBase.__new__` metaclass at the instant its `class` statement runs — and that metaclass needs to know which installed application owns the model, while cross-app foreign keys routinely point at models whose modules have not been imported yet. `Apps.populate` breaks both cycles by forbidding model imports until all `AppConfig` instances exist (Phase 1), queuing unresolved cross-app foreign keys as curried callbacks in `_pending_operations` while models import (Phase 2), and withholding `AppConfig.ready` until every model in the project is registered (Phase 3).

That design makes ordinary Django apps feel effortless — until code violates the phase order, runs database queries before migrations exist, or mutates `settings` after startup without notifying the subsystems that cached old values. We start at the very first line of boot, with the proxy that makes importing `settings` safe at any time, in [Lazy settings and configuration](startup/lazy-settings.md).
