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
