Index: middleware/smartslash.py
===================================================================
--- middleware/smartslash.py	(revision 0)
+++ middleware/smartslash.py	(revision 0)
@@ -0,0 +1,22 @@
+from django.core import urlresolvers
+from django import http
+
+class SmartSlashMiddleware(object):
+    """
+    If the initial response is 404, and the initial path doesn't end with a slash,
+    a new URL is formed by appending a slash.
+    If the new URL is found in urlpatterns, then an HTTP-redirect to the new URL is returned.
+    """
+
+    def process_response(self, request, response):
+        path = request.path
+        if response.status_code == 404 and path[-1] != '/':
+            newpath = path + '/'
+            try:
+                urlresolvers.resolve(newpath)
+            except urlresolvers.Resolver404:
+                pass
+            else:
+                newurl = http.build_url(request, newpath) 
+                response = http.HttpResponsePermanentRedirect(newurl)
+        return response
