[docs]def__call__(self,request):"""Add or remove trailing slashes where needed. Note that there is no HTTP redirection actually happening. This just fixes the trailing slashes before the URLs are matched to any URL patterns by changing the request's internal properties. """# We can't remove slashes from these urls - they're included from# first/third party appsexception_prefixes=["/admin","/api-auth","/djangoadmin","/__debug__","/oauth"]needs_trailing_slash=Falseforprefixinexception_prefixes:needs_trailing_slash|=request.path.startswith(prefix)ifneeds_trailing_slash:ifnotrequest.path.endswith("/"):new_url=request.path+"/"request.path_info=new_urlrequest.path=new_urlelifrequest.path!="/":ifrequest.path.endswith("/"):new_url=request.path.rstrip("/")request.path_info=new_urlrequest.path=new_urlreturnself.get_response(request)