Step 1 — Read the Error Message Carefully
The error message usually tells you exactly what is wrong.
Examples:
TemplateDoesNotExist
Meaning: - Django cannot find the HTML template file - Usually caused by: - wrong folder structure - wrong template path - missing file
NoReverseMatch
Meaning:
- Django cannot find a URL name
- Usually caused by:
- wrong URL name in urls.py
- typo in {% url %} tag
Example:
return render(request, "core/login.html")
If the file is not inside the correct templates folder:
TemplateDoesNotExist
will appear.
Always read: - Exception type - Exception message
before changing code.
Step 2 — Check the Terminal
Always watch the terminal where the Django server is running.
Example:
python manage.py runserver
When an error happens: - Django prints the full traceback - Shows: - file name - line number - exact error
Example:
File "views.py", line 12
This tells you exactly where the issue happened.
The terminal is one of the best debugging tools.
Step 3 — Check Django's Browser Error Page
When DEBUG=True, Django shows a detailed error page.
It includes:
- Exception type
- Exception value
- Which view caused the error
- Full traceback
- Variables and request details
Example:
TemplateDoesNotExist at /login/
This helps you understand: - what failed - where it failed - why it failed
Read the error page slowly.
Most answers are already there.
Step 4 — Isolate the Problem
Do not change many things at once.
Remove code until the error disappears.
Then add code back step by step.
Example:
Full template → broken
Try:
hello world
If that works:
Add extends → works
Then:
Add full content → broken
Now you know: - the problem is inside the template content - not in the view - not in the URL - not in Django
This method helps you find the exact problem quickly.
Step 5 — Check the Basics
Many bugs are simple mistakes.
Always check:
- Is the server running?
- Did you save the file?
- Is the file in the correct folder?
- Does the URL match
urls.py? - Is the template name correct?
- Is there a typo?
90% of bugs are caused by basic issues.
Useful Django Debug Commands
Check if Django Can Find a Template
python manage.py shell -c "import django; print(django.template.loader.get_template('core/login.html'))"
What this does:
- Opens Django shell
- Tries loading the template
- Prints the result
If Django finds the template: - the file path is correct
If not: - Django raises:
TemplateDoesNotExist
Useful for debugging template path issues.
Check for Project Errors
python manage.py check
This checks: - project configuration - app configuration - model problems - URL issues
Useful before running the server.
Open Django Interactive Shell
python manage.py shell
Used for: - testing queries - testing imports - debugging models - checking database data
Example:
from blog.models import Post
Post.objects.all()
Show All URLs
python manage.py show_urls
Useful for checking: - registered URLs - URL names - route conflicts
Note: This command usually requires installing:
django-extensions
Install:
pip install django-extensions
Understanding find . -name "*.html"
This is a Linux terminal command.
Example:
find . -name "*.html"
What It Means
find
Search for files and folders.
.
Start searching from the current folder.
-name
Search by file name.
"*.html"
Find all files ending with .html.
Example
Suppose your project contains:
templates/base.html
core/templates/core/login.html
blog/templates/blog/post.html
Running:
find . -name "*.html"
will show:
./templates/base.html
./core/templates/core/login.html
./blog/templates/blog/post.html
Why This Is Useful
Useful for debugging: - missing templates - wrong folder structure - duplicate template files
If Django says:
TemplateDoesNotExist
You can quickly verify: - whether the file exists - where it exists
Final Advice
Debugging is not guessing.
Good debugging means:
- Read the error
- Check the traceback
- Isolate the issue
- Test step by step
- Verify basics first
The more you debug carefully, the faster you improve as a developer.