Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #4049 -- Improved error handling in auth() context processor. B…

…ased on a patch from gregorth.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6356 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c694587ebbf7a45d3e6f91f5bfc4e81001c03d97 1 parent e988aa3
@malcolmt malcolmt authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 django/core/context_processors.py
View
14 django/core/context_processors.py
@@ -13,11 +13,19 @@ def auth(request):
"""
Returns context variables required by apps that use Django's authentication
system.
+
+ If there is no 'user' attribute in the request, uses AnonymousUser (from
+ django.contrib.auth).
"""
+ if hasattr(request, 'user'):
+ user = request.user
+ else:
+ from django.contrib.auth.models import AnonymousUser
+ user = AnonymousUser()
return {
- 'user': request.user,
- 'messages': request.user.get_and_delete_messages(),
- 'perms': PermWrapper(request.user),
+ 'user': user,
+ 'messages': user.get_and_delete_messages(),
+ 'perms': PermWrapper(user),
}
def debug(request):

0 comments on commit c694587

Please sign in to comment.
Something went wrong with that request. Please try again.