๐ฏ Objective
To create a custom 500 error page for server-side errors.
โ What is 500 Error?
500 error occurs when:
- Server crashes
- Code error occurs
- Internal server issue
๐ Step 1: Create Template
templates/500.html
<!DOCTYPE html>
<html>
<head>
<title>Server Error</title>
</head>
<body>
<h1>500 Error</h1>
<p>Something went wrong. Please try again later.</p>
</body>
</html>
โ๏ธ Step 2: Configure Settings
# settings.py
DEBUG = False
ALLOWED_HOSTS = ['*']
๐ Step 3: Add Handler
# project urls.py
handler500 = 'yourapp.views.custom_500'
๐ง Step 4: Create View
# views.py
def custom_500(request):
return render(request, '500.html', status=500)
๐งช Step 5: Test It
Add temporary error:
def test_error(request):
x = 10 / 0 # Will crash
Visit this URL โ triggers 500 page
โ ๏ธ Important Notes
- Works only when
DEBUG = False - Used in production
- Helps improve user experience
๐ง Exam Tips
- 500 = Internal Server Error
- Must define
handler500 - Template name โ
500.html - No exception parameter required
๐ฅ Viva Questions
- What is 500 error?
- Difference between 404 and 500?
- Why use custom error pages?
- How to trigger 500 error?
- Does it work when DEBUG = True?
Further Reading
Introduction to Django Framework and its Features
Examples of Array Functions in PHP
Registration Form Using PDO in PHP
Inserting Information from Multiple CheckBox Selection in a Database Table in PHP
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
