c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
Python

How to create custom 404 error page in Django?

| | django , python

In this tutorial I will show you how to create custom 404 error page for a Django project.

Creating a custom 404 page provides a user-friendly informative message when a page is not found. Instead of a "Page Not Found" message,  show your custom 404 page.

Solution:

1.Ensure that Django project is configured to use custom error pages by setting DEBUG = False in settings.py.

2.In templates directory, create a file named 404.html.

Example 404 Page:

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Not Found</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
h1 {
font-size: 3em;
color: #ff6f61;
}
p {
font-size: 1.5em;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>404 - Page Not Found</h1>
<p>Sorry, the page you are looking for does not exist.</p>
<a href="/">Return to Home</a>
</body>
</html>

VIDEO GUIDE: