1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #mymiddleware.py
class RedirectToNoSlash(object):
def process_request(self,request):
if '/admin' not in request.path and request.path != '/':
if request.path[-1] == '/':
return HttpResponsePermanentRedirect(request.path[:-1])
#settings.py
MIDDLEWARE_CLASSES = (
'mymiddleware.RedirectToNoSlash',
...
)
#Make sure its the first middleware, or its before any url manipulating middleware such as CommonMiddleware.
|
More like this
- Create short URL redirects for site urls. by matt.geek.nz 4 years, 3 months ago
- Smart append slash middleware by akaihola 5 years, 3 months ago
- PermanentRedirectMiddleware by marinho 4 years, 10 months ago
- Save disk space by hard-linking multiple Django installations by akaihola 6 years, 1 month ago
- RedirectedURLField by stringify 3 years, 3 months ago
Comments
isn't that obsolet?
https://docs.djangoproject.com/en/dev/ref/settings/#append-slash
#