Flavio Milan
Flavio Milan

Reputation: 487

Django - error_403() got an unexpected keyword argument 'exception'

When the user is not allowed to see the contents of the instance, when the PermissionDenied exception was thrown, instead of forwarding it to the 404.html template, it has an error.

DetailView:

class OccurrenceDetail(OccurrenceModel, BaseDetailViewWithLogin):
    permission_required = ('occurrences.see_occurrence')

    def get_object(self, queryset=None):
        perm = self.request.user.has_perm(self.permission_required)
        obj = super(OccurrenceDetail, self).get_object(queryset=queryset)
        if not perm:
            raise PermissionDenied()
        return obj

Urls:

handler403 = 'apps_core.core.views.error_403'

Views:

def error_403(request):
    data = {}
    return render(request,'errors/403.html', data)

Upvotes: 3

Views: 1530

Answers (1)

Ralf
Ralf

Reputation: 16505

The 403 error view expects a second argument, which is the raised exception.

To solve it, you can change your code to:

def error_403(request, exception):
    ...

or something more general

def error_403(request, *args, **kwargs):
    ...

Upvotes: 8

Related Questions