1
0
Fork 0
mirror of https://github.com/Findus23/acronomy.git synced 2024-09-19 15:33:45 +02:00
acronomy/common/redirect.py
2020-07-06 19:54:36 +02:00

22 lines
674 B
Python

from django.http import HttpResponseRedirect
class NoTrailingSlashMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
old_url: str = request.path
if (
old_url.endswith('/')
and not old_url.startswith("/admin")
and not old_url.startswith("/__debug__")
and not old_url.startswith("/account")
and not old_url.startswith("/api")
and not old_url == "/"
):
new_url = old_url[:-1]
return HttpResponseRedirect(new_url)
return self.get_response(request)