What does setting DEBUG = True do in a Django project?
It enables detailed error pages with debug information and auto-reloads the server on code changes. It should only be used during development.
Click to reveal answer
beginner
Why should DEBUG be set to False in production?
Because detailed error pages can expose sensitive information to users, which is a security risk. Also, performance is better with DEBUG = False.
Click to reveal answer
intermediate
What happens if DEBUG = True but ALLOWED_HOSTS is not set correctly?
Django will allow all hosts when DEBUG = True, but in production with DEBUG = False, ALLOWED_HOSTS must list allowed domains to prevent host header attacks.
Click to reveal answer
intermediate
How does DEBUG = True affect static file serving in Django?
When DEBUG = True, Django automatically serves static files during development. When DEBUG = False, static files must be served by a web server or CDN.
Click to reveal answer
intermediate
What is the impact of DEBUG = True on database queries?
Django logs detailed SQL queries and timing information in the debug toolbar or console, helping developers optimize queries during development.
Click to reveal answer
What is the main purpose of setting DEBUG = True in Django?
AImprove production server performance
BShow detailed error pages and auto-reload during development
CDisable error messages
DEnable database backups
✗ Incorrect
DEBUG = True shows detailed error pages and reloads the server automatically to help developers during development.
What risk does leaving DEBUG = True in production pose?
APrevents database connections
BSlows down the server
CDisables static files
DExposes sensitive information to users
✗ Incorrect
Detailed error pages can reveal sensitive data, which attackers could exploit.
When DEBUG = False, what must be properly configured to avoid errors?
AINSTALLED_APPS
BDATABASES
CALLOWED_HOSTS
DSTATIC_URL
✗ Incorrect
ALLOWED_HOSTS must list allowed domains to prevent host header attacks when DEBUG is False.
How does Django handle static files when DEBUG = True?
ADjango serves static files automatically
BStatic files must be served by a web server
CStatic files are disabled
DStatic files are compressed
✗ Incorrect
Django serves static files automatically during development when DEBUG is True.
Which tool benefits from DEBUG = True by showing SQL queries?
ADjango Debug Toolbar
BDjango Admin
CDjango ORM
DDjango Migrations
✗ Incorrect
The Django Debug Toolbar shows detailed SQL queries and timings when DEBUG is True.
Explain what happens when you set DEBUG = True in a Django project and why it is useful during development.
Think about how developers find and fix errors quickly.
You got /4 concepts.
Describe the security and configuration considerations when switching DEBUG from True to False in Django.
Focus on what changes to keep the site safe and working.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of setting DEBUG = True in a Django project?
easy
A. To enable database backups automatically
B. To improve website speed in production
C. To disable all logging
D. To show detailed error messages during development
Solution
Step 1: Understand the role of DEBUG in Django
DEBUG mode is designed to help developers by showing detailed error messages and debugging information.
Step 2: Identify the correct purpose
Setting DEBUG = True enables detailed error pages, which is useful only during development, not production.
Final Answer:
To show detailed error messages during development -> Option D
Quick Check:
DEBUG = True shows errors [OK]
Hint: DEBUG = True means show errors for fixing [OK]
Common Mistakes:
Thinking DEBUG improves production speed
Confusing DEBUG with logging settings
Assuming DEBUG enables backups
2. Which of the following is the correct way to disable debug mode in Django's settings.py?
easy
A. DEBUG = False
B. DEBUG = 'False'
C. debug = False
D. DEBUG = 0
Solution
Step 1: Check the correct syntax for boolean in Python
In Python, boolean values are capitalized: True or False without quotes.
Step 2: Identify the correct assignment in settings.py
DEBUG must be assigned the boolean False, not a string or lowercase variable.
Final Answer:
DEBUG = False -> Option A
Quick Check:
Boolean False without quotes disables debug [OK]
Hint: Use capitalized False without quotes to disable debug [OK]
Common Mistakes:
Using 'False' as a string instead of boolean
Using lowercase debug variable
Assigning numeric 0 instead of False
3. Given the following Django settings snippet:
DEBUG = True
ALLOWED_HOSTS = []
What will happen if you access the site from a browser?
medium
A. The site will redirect to a login page
B. The site will show a detailed error page if an error occurs
C. The site will run normally without errors
D. The site will block all hosts and show a 400 error
Solution
Step 1: Understand DEBUG and ALLOWED_HOSTS interaction
When DEBUG is True, Django ignores ALLOWED_HOSTS restrictions and shows detailed errors.
Step 2: Predict behavior on error
If an error occurs, Django will display a detailed debug page to help fix it.
Final Answer:
The site will show a detailed error page if an error occurs -> Option B