0
0
Djangoframework~5 mins

DEBUG mode behavior in Django

Choose your learning style9 modes available
Introduction

DEBUG mode helps you see detailed error messages and extra information while building your website. It makes fixing problems easier.

When you are developing a new Django website and want to find mistakes quickly.
When you want to see detailed error pages with helpful hints.
When you want to test changes before making your site live.
When you want to see SQL queries Django runs to optimize your code.
Syntax
Django
DEBUG = True

This line goes in your settings.py file.

Set DEBUG = False when your site is ready for real users to keep it safe.

Examples
Turn on debug mode to see detailed error pages and extra info.
Django
DEBUG = True
Turn off debug mode for production to hide error details and improve security.
Django
DEBUG = False
Sample Program

With DEBUG = True, if an error happens (like dividing by zero), Django shows a detailed error page with the problem and where it happened.

When DEBUG = False, Django shows a simple error page without details.

Django
# settings.py
DEBUG = True

# views.py
from django.http import HttpResponse

def home(request):
    # This will cause an error if uncommented
    # 1 / 0
    return HttpResponse('Hello, world!')
OutputSuccess
Important Notes

Never leave DEBUG = True on a live website because it can show sensitive information to visitors.

When DEBUG is True, Django serves static files automatically for convenience.

Use DEBUG to help during development, but always test with DEBUG = False before going live.

Summary

DEBUG mode shows detailed error info to help fix problems.

Use DEBUG = True only during development.

Set DEBUG = False for production to keep your site safe.