Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Improved the auth admin site to raise Http404 with a helpful error me…

…ssage if DEBUG is True, explaining why permission isn't denied. Refs #9866, and see also [9682]

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit be2697209bdffa8807140a01f43bee024c5a2bfd 1 parent 62362c6
@adrianholovaty adrianholovaty authored
Showing with 9 additions and 5 deletions.
  1. +9 −5 django/contrib/auth/
14 django/contrib/auth/
@@ -1,14 +1,14 @@
+from django import template
+from django.conf import settings
+from django.contrib import admin
+from django.contrib.auth.forms import UserCreationForm, UserChangeForm, AdminPasswordChangeForm
from django.contrib.auth.models import User, Group
from django.core.exceptions import PermissionDenied
-from django import template
+from django.http import HttpResponseRedirect, Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.utils.html import escape
-from django.http import HttpResponseRedirect
from django.utils.translation import ugettext, ugettext_lazy as _
-from django.contrib.auth.forms import UserCreationForm, UserChangeForm, AdminPasswordChangeForm
-from django.contrib import admin
class GroupAdmin(admin.ModelAdmin):
search_fields = ('name',)
@@ -49,6 +49,10 @@ def add_view(self, request):
# disallow users from adding users if they don't have change
# permission.
if not self.has_change_permission(request):
+ if self.has_add_permission(request) and settings.DEBUG:
+ # Raise Http404 in debug mode so that the user gets a helpful
+ # error message.
+ raise Http404('Your user does not have the "Change user" permission. In order to add users, Django requires that your user account have both the "Add user" and "Change user" permissions set.')
raise PermissionDenied
if request.method == 'POST':
form = self.add_form(request.POST)

0 comments on commit be26972

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