blob: 0fde6c0b76be299b7dc86d233d69795b5d526ca4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from django.http import HttpResponsePermanentRedirect
class RemoveSlashMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if '/admin' in request.path and not request.path.endswith('/'):
return HttpResponsePermanentRedirect(request.path + '/')
if request.path != '/' and request.path.endswith('/') and "/admin/" not in request.path:
return HttpResponsePermanentRedirect(request.path[:-1])
return self.get_response(request)
|