-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(error-handling): custom 404 handler (#102)
- Create a custom 404 Not Found page and improve the handler404 with a better 404.html template - Add comments, formatting, and pylint suppressions to satisfy pylint - Apply Black formatting - Remove unnecessary DEBUG line
- Loading branch information
1 parent
e846521
commit 69cb0bf
Showing
3 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %} | ||
Oops | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Oops</h1> | ||
<h2>We can't seem to find the page you are looking for.</h2> | ||
{% endblock%} | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="p-3 col-12"> | ||
<h3>404</h3> | ||
<h5>Page not found</h5> | ||
<br> | ||
<p> | ||
We couldn't find a page at this address. | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Module for custom error views. | ||
""" | ||
|
||
from django.http import HttpRequest, HttpResponse | ||
from django.shortcuts import render | ||
|
||
|
||
# pylint: disable=unused-argument | ||
def custom_404_page_not_found( | ||
request: HttpRequest, exception: Exception | ||
) -> HttpResponse: | ||
""" | ||
Custom view to handle 404 errors. | ||
Args: | ||
request (HttpRequest): The request object. | ||
exception (Exception): The exception that triggered the 404 error. | ||
Returns: | ||
HttpResponse: Rendered 404 error page. | ||
""" | ||
return render(request, "404.html", status=404) |