Skip to content

Commit d592ca4

Browse files
Fixed django#2541 -- Added helpful error message for CacheMiddleware in the case of CACHE_ANONYMOUS_ONLY=True and uninstalled/unordered AuthenticationMiddleware. Thanks, dummy@habmalnefrage.de
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 8f065bb commit d592ca4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

django/middleware/cache.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def __init__(self, cache_timeout=None, key_prefix=None, cache_anonymous_only=Non
4141

4242
def process_request(self, request):
4343
"Checks whether the page is already cached and returns the cached version if available."
44+
if self.cache_anonymous_only:
45+
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."
46+
4447
if not request.method in ('GET', 'HEAD') or request.GET:
4548
request._cache_update_cache = False
4649
return None # Don't bother checking the cache.

0 commit comments

Comments
 (0)