Django

Django Practice

Master production-ready Django by solving hands-on challenges, one concept at a time.

Django 5.2Django 5.2Python 3.13Python 3.13
Read the Django overview
Module 1

Models & Relationships

Unlock the database layer of your applications with this comprehensive module on Django Models & Relationships

4
About this challenge

Products lose data: prices come back wrong, names have no length limit, and nothing records when an item was added. Define a Product model with a bounded name, an exact decimal price, a stock count with a sensible default, an active flag, an auto-set creation time and a readable string form.

About this challenge

Books and authors live in unrelated tables, so deleting an author leaves orphaned books. Relate Book to Author so an author's books go with the author and are listed through the author, and add an optional publisher that cannot be deleted while it still has books.

About this challenge

Students take many courses, courses have many students, and each student has exactly one transcript. Model the many-to-many and the one-to-one, readable from both sides, with at most one transcript per student enforced by the database.

About this challenge

Model a library from scratch: members, books, authors, loans and member cards. Use every relationship kind: books to authors (many-to-many), loans that link a member and a book and carry their own due date, and one card per member, with delete rules and readable string forms throughout.

Module 2

QuerySets & ORM Basics

Query the database through the ORM: filter, order, shape results, and fetch single objects safely in one query.

4
About this challenge

The product search returns everything no matter what the user asks for. Filter products by a case-insensitive name match and an inclusive price range, leave out inactive items, sort by price then name, and answer in a single database query.

About this challenge

A report needs items in the right order, only a few columns, and just the latest rows. Add chainable QuerySet methods that sort by name or newest first, take the top N, and return plain dicts or a flat list of names.

About this challenge

Detail lookups crash on unknown products and silently pick a random row when names repeat. Fetch single products safely by sku and by name, ignore discontinued items, and answer "any products?" and "how many?" without loading rows.

About this challenge

Support needs one set of catalog answers they can trust. Build query functions for search, newest items, price lists, name lists and single lookups, each skipping inactive products and running exactly one query.

Module 3

URLs & Views

Route requests with path converters and named URLs, and return safe HTML, redirect, and JSON responses.

4
About this challenge

Only the home page is routed, so every article URL is a 404. Route articles by id, slug and four-digit year so the view receives typed values and malformed URLs are rejected before any view runs.

About this challenge

Links and redirects break every time a URL changes. Name the routes inside an app namespace, build every link from those names, and send old post URLs to their new home with a permanent redirect.

About this challenge

Product pages need a safe detail view and a JSON endpoint. Return the product page or a 404 for unknown ids, and serve the same product as properly encoded JSON with its price as a two-decimal string.

About this challenge

A recipe site needs its whole request layer built. Add namespaced routes for the list, detail, year archive, JSON API and a legacy redirect, with typed URL arguments, 404s for bad input, and every URL built from its route name.

Module 4

Templates

Render pages with the Django template language: filters, loops, conditions, includes, and template inheritance.

4
About this challenge

The product page has no template yet. Render the product from a template with a readable release date, a fallback for a missing manufacturer, a short description teaser and prices that always show two decimals.

About this challenge

Every product row in the listing looks the same. Number the rows, alternate their styling, show a sold-out or low-stock badge from a reusable partial, and show a friendly message when the list is empty.

About this challenge

Every page would need its own copy of the HTML skeleton and navbar. Build a base template with title and content blocks and an included navbar whose links come from URL names, then have each page extend it.

About this challenge

A storefront needs its list and detail pages built on a shared layout. Link each product row to its detail page, reuse one stock badge on both pages, format prices to two decimals, and show a teaser in the list and the full description on the detail page.

Module 5

Django Admin

Run a back office on the admin site: registrations as the access decision, configured change lists, computed columns, inlines, and bulk actions.

4
About this challenge

Register the catalogue models with the Django admin so staff can create, edit and delete records through the interface.

About this challenge

Configure a Django admin change list with columns, a computed column, search, sidebar filters and a default order.

About this challenge

Edit order items inline on the order page, show a read-only computed total and add a bulk admin action.

About this challenge

Configure a complete Django admin back office: change lists with computed columns, search, filters, ordering, inline editing, read-only totals, a bulk action and correct registration scope.

Module 6

Static & Media Files

Serve the assets that ship with the code and the files users upload, each resolved through its own tag and kept in its own root.

4
About this challenge

Serve a stylesheet and a logo through Django's static files: the app static layout and the static template tag instead of hardcoded paths.

About this challenge

Accept a validated PDF upload through a Django form and store it under MEDIA_ROOT, with the multipart encoding the browser needs.

About this challenge

Add an image field with an upload-to path and render the stored image's URL, falling back to a static placeholder.

About this challenge

Build a photo gallery end to end: static assets through the static tag, validated image uploads into a dated media path, and a listing with a placeholder fallback.

Module 7

Class-Based Views

Replace hand-rolled views with generic class-based views: list, detail, create, update and delete, paginated, gated and owner-scoped.

4
About this challenge

Configure a Django ListView with its template, context name, ordering and built-in pagination.

About this challenge

Wire a DetailView and a CreateView with a form class, redirecting to the new object through get_absolute_url.

About this challenge

Restrict UpdateView and DeleteView to the signed-in user's own objects by overriding get_queryset, with login required and defined redirects.

About this challenge

Build a complete CRUD surface with generic class-based views: paginated owner-scoped list with extra context, detail, create attaching the owner server-side, and scoped update and delete behind a login gate.

About this path

This path covers the core of a Django 5.2 site: models and relationships, QuerySets and the ORM, URLs and views, and templates. You should be able to write basic Python before you start. No earlier Django experience is needed. The templates module renders real pages from your data and ends with a small storefront.

Frequently asked questions

4

What will I practice in this path?

7 modules: Models & Relationships, QuerySets & ORM Basics, URLs & Views, Templates, Django Admin, Static & Media Files and Class-Based Views.

How many challenges are there, and how hard are they?

28 challenges: 24 easy and 4 medium.

What does this path run on?

Challenges run on Django 5.2 and Python 3.13.

Do I need to install anything?

No. Every challenge runs in a browser-based IDE with everything already set up, and your code is graded automatically against a test suite.

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.