mirror of
https://github.com/Findus23/acronomy.git
synced 2024-09-11 06:23:44 +02:00
22 lines
674 B
Python
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)
|