-1

I have a permission that works on a view:

@permission_required('app.admin_foo')
def fooView(request, id=None):
    ...

But the default behaviour is to redirect to a login. How can I get Django to redirect to another view when the permission is denied? E.g.

return redirect(reverse('bar'))

Update

For your information, Django can be set up to redirect to a custom 403 page when a permission check fails. See Flimm's answer on this page: Django, creating a custom 500/404 error page

gornvix
  • 2,916
  • 4
  • 29
  • 63

1 Answers1

2

The permission_required decorator accepts a login_url parameter, this parameter is the url that the user will be redirected to instead of the default settings.LOGIN_URL

@permission_required('app.admin_foo', login_url='/foo/')
def fooView(request, id=None):
    ...
Iain Shelvington
  • 26,159
  • 1
  • 24
  • 40