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

23 lines
674 B
Python
Raw Permalink Normal View History

2020-06-15 22:37:20 +02:00
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")
2020-07-06 19:54:36 +02:00
and not old_url.startswith("/__debug__")
2020-07-02 21:49:48 +02:00
and not old_url.startswith("/account")
2020-06-15 22:37:20 +02:00
and not old_url.startswith("/api")
and not old_url == "/"
):
new_url = old_url[:-1]
return HttpResponseRedirect(new_url)
2020-06-15 22:39:24 +02:00
return self.get_response(request)