Django

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

You may also like...

Leave a Reply

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