Created
August 29, 2024 20:04
-
-
Save dryan/fd8fee493471b88e8bcaeabfbb89af90 to your computer and use it in GitHub Desktop.
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
from django.views.defaults import page_not_found as django_page_not_found | |
from django.views.decorators.csrf import requires_csrf_token | |
from django.views.defaults import ERROR_404_TEMPLATE_NAME | |
@requires_csrf_token | |
def page_not_found(request, exception, template_name=ERROR_404_TEMPLATE_NAME): | |
path = request.path.strip("/") | |
# custom logic goes here | |
# see if there's a lowercase match | |
if request.path != request.path.lower(): | |
try: | |
view, args, kwargs = resolve(request.path.lower()) | |
view(*args, **kwargs) | |
return http.HttpResponseRedirect(request.path.lower()) | |
except Exception: | |
# do nothing so we return the original exception | |
pass | |
return django_page_not_found(request, exception, template_name=template_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment