Django Ninja Quickstart

Our copy of the Django Ninja Quick Start, adapted for uv and the chat app in your locallibrary project.

In three short pages you’ll build a small chat API for the chat rooms in your locallibrary: people can browse rooms, filter and paginate them, read a room’s messages, sign in, and post a message that shows up live in the chat page. Along the way you’ll see most of what makes Django Ninja pleasant to use: type hints that validate input, schemas generated from your models, interactive docs, auth, and routers.

This guide assumes you already know Django: projects, apps, models and migrations. It won’t explain those; it only shows the Django Ninja parts.

Page What you’ll do
1. First API Install, create an API, write an endpoint, open the interactive docs
2. Models & Schemas Save chat rooms and messages to the database, then full CRUD for the Room model, plus pagination and filtering
3. Auth, Routers & Next Steps Split the API into a router, require login, let users post messages to a room

Before you start

We assume that you have completed preps 01-06 (our fork of the MDN Django Tutorial through Part 8) and all four parts of our Channels tutorial. You have your locallibrary repository: a uv project with manage.py, pyproject.toml, and uv.lock at its root, the locallibrary_config project package, the catalog app, and the asynchronous chat app. Every command in this guide is run from that root folder.

The chat app works, but it forgets everything: a message exists only while it travels through Redis to the browsers in the room. An API that lists rooms and messages needs them in the database. So before the Django Ninja parts, page 2 adds Room and Message models to the chat app, saves every message to the database, and shows a room’s history when you open it.

How this copy differs from the original

This is a copy of the official Django Ninja Quick Start, changed to match the way we have worked in our fork of the MDN Django Tutorial and our Channels tutorial:

  • You don’t create a new project or app. The API goes into your existing locallibrary repository. Everywhere the original says mysite, this copy says locallibrary_config, and the original’s events app is your chat app.
  • Chat rooms instead of events. The original builds an API for an Event model, and users register for events. This copy builds the same API for a Room model, and users post Messages to rooms. Each piece of the original has a counterpart here: EventFilter’s upcoming filter becomes RoomFilter’s recent filter, the 409 for an event that clashes with another becomes a 409 for a room name that’s taken, and the nested RegistrationOut schema becomes a nested MessageOut schema.
  • You add models to the chat app first. Page 2 starts with Room and Message models, saves messages from the WebSocket consumer, and shows a room’s saved messages when you open it. The original has nothing like this, because it starts from an empty app.
  • Posted messages go to the chat page. On page 3, a message posted through the API is also sent to everyone in the room over the channel layer, so it appears in the chat page right away.
  • Dependencies are managed with uv. pip install becomes uv add, and every command is run with uv run python ….
  • Edits to existing files are additions. The original shows complete urls.py contents because it assumes a new, empty project. Here you only add lines, so you keep what you built for catalog and chat.

This copy follows the Django Ninja documentation as of 2026-10-19 (Django Ninja 1.7.1), on Django 6.1, Channels 4.3, and Python 3.14. Once you finish, continue with our Django Ninja Tutorial.


The original Quick Start is Copyright (c) 2025 Vitaliy Kucheryaviy, and is used under its MIT license.


Quick Start Part 1: First API

Install Django Ninja, create an API in locallibrary, write an endpoint, and open the interactive docs.

Quick Start Part 2: Models & Schemas

Save chat rooms and messages to the database, then build a CRUD API for rooms with pagination and filtering.

Quick Start Part 3: Auth, Routers & Next Steps

Move the endpoints into the chat app, require login for writes, and let signed-in users post messages to a room.

Last modified October 22, 2026: add button label (28b88d0)