Commits

Anonymous committed 17f922b

Fixed #2541 -- Added helpful error message for CacheMiddleware in the case of CACHE_ANONYMOUS_ONLY=True and uninstalled/unordered AuthenticationMiddleware. Thanks, dummy@habmalnefrage.de

  • Participants
  • Parent commits 2607fbb

Comments (0)

Files changed (1)

django/middleware/cache.py

 
     def process_request(self, request):
         "Checks whether the page is already cached and returns the cached version if available."
+        if self.cache_anonymous_only:
+            assert hasattr(request, 'user'), "The Django cache middleware with CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True requires authentication middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the CacheMiddleware."
+
         if not request.method in ('GET', 'HEAD') or request.GET:
             request._cache_update_cache = False
             return None # Don't bother checking the cache.