API Reference

Django

Batteries-included Python web framework with ORM, migrations, admin, templates and security defaults.

Official Documentation ↗
CompatibilityThis documentation covers version Django 5.0+ / Python 3.10+. Check the official docs for the latest API surface.

Installation

pippip install django

Methods

Overview

Django is a full web framework: it provides an ORM, migrations, an admin interface, templating, forms and security defaults, so most applications need little additional infrastructure.

Core Methods

Models map to tables, QuerySets build queries lazily, and views return responses. Migrations version schema changes, and the admin exposes models for management.

Usage Notes

Keep queries efficient with select_related and prefetch_related, split settings by environment, and run deployment checks before production. Use the admin for internal tools.

Common Pitfalls

Iterating a queryset and touching related fields causes N+1 queries. Storing business logic in views instead of models or services hurts reuse. Leaving DEBUG on in production leaks sensitive details.

FAQ

How do I avoid N+1 queries?
Use select_related for foreign keys and prefetch_related for many-to-many and reverse relations so related rows load in one query instead of per object.
When should I use async views?
Django supports async views and the ORM uses a sync-to-async boundary. Use async for I/O-bound endpoints, but be aware the ORM call is still synchronous under the hood.
How does Django handle security by default?
It enables CSRF protection, escapes template variables, hashes passwords with a strong algorithm, and warns about risky settings. Review deployment checks before going live.