-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
  • 3,154
  • 6
  • 35
  • 74

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
  • 31,030
  • 3
  • 31
  • 50