http404 django

To handle a 404 error in Django, follow these steps:

  1. Create a new view function to handle the 404 error.
from django.shortcuts import render

def handle_404(request, exception):
    return render(request, '404.html', status=404)
  1. In your Django project's urls.py file, include the new view function for handling the 404 error.
from django.urls import path
from . import views

handler404 = 'yourapp.views.handle_404'
  1. Create a 404.html template in your templates directory to customize the 404 error page.
<!DOCTYPE html>
<html>
<head>
    <title>Page Not Found</title>
</head>
<body>
    <h1>404 - Page not found</h1>
    <p>The page you are looking for does not exist.</p>
</body>
</html>