Create and Configure a Custom 500 Error Page

🎯 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

  1. What is 500 error?
  2. Difference between 404 and 500?
  3. Why use custom error pages?
  4. How to trigger 500 error?
  5. Does it work when DEBUG = True?

Further Reading

Introduction to Django Framework and its Features

Django Practice Exercise

Examples of Array Functions in PHP

Basic Programs in PHP

Registration Form Using PDO in PHP

Inserting Information from Multiple CheckBox Selection in a Database Table in PHP

programmingempire

princites.com

Leave a Reply

Your email address will not be published. Required fields are marked *