Skip to content

Instantly share code, notes, and snippets.

@JamieRobertson
JamieRobertson / slash_middleware.py
Created August 16, 2017 21:20 — forked from gregplaysguitar/slash_middleware.py
Append OR remove slash in django - like APPEND_SLASH but smarter.
from django import http
from django.utils.http import urlquote
from django import urls
from django.conf import settings
from django.utils.deprecation import MiddlewareMixin
class AppendOrRemoveSlashMiddleware(MiddlewareMixin):
"""Like django's built in APPEND_SLASH functionality, but also works in
reverse. Eg. will remove the slash if a slash-appended url won't resolve,