liveBook · Manning

Debugging mode

As explained in Django in Action

DEBUG is a Django setting that controls whether detailed diagnostic information is displayed for errors.

Debugging mode is controlled by Django’s DEBUG setting. With DEBUG=True, errors reveal what went wrong; with DEBUG=False, visitors receive a safer, generic error page. section 4.6.1

A missing musician

Requesting /bands/musician/100/ when no musician has ID 100 produces a 404. Development mode displays the failed query and matched URL patterns; production mode shows little information. A coding mistake instead produces a 500 page, with a stack trace in development. section 4.6.1

Listing 4.4 A view for displaying a Musician object based on an argument
# RiffMates/bands/views.py
from django.shortcuts import render, get_object_or_404  #1

from bands.models import Musician  #2

def musician(request, musician_id):
    musician = get_object_or_404(Musician, id=musician_id)  #3

    data = {
        "musician": musician, #4
    }

    return render(request, "musician.html", data)

The musician view uses get_object_or_404(), making it a practical starting point for observing how DEBUG changes error details. section 4.6.1

How Django in Action covers it

How deep it goes
Explains visible 404 and 500 behavior, including URL diagnostics and stack traces, but not DEBUG configuration steps.
Examples
Uses a nonexistent musician ID, a musician detail URL, and coding errors to demonstrate diagnostic pages.
What it assumes
Assumes basic Django views, URL arguments, Http404 responses, and development-versus-production environments.
What you can do after
Diagnose/debug URL and application failures by reading Django’s development error details.
How it connects
Connects Django settings to Http404, get_object_or_404(), URL routing, and stack traces.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.