Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - redirect to login page vs. 403

Tags:

django

login

Why does Django redirects user to login page when trying to access pages protected by permissions? Wouldn't it make more sense to raise 403? Then I could display meaningful message in 403.html (using custom middleware) to user saying they don't have permissions to perform the action. Also I would be able to identify links to views that user shouldn't even be presented with at first place or users trying to access forbidden resources.

like image 510
Tomas Avatar asked Dec 03 '10 21:12

Tomas


1 Answers

For future googlers, the permission_required decorator accepts an optional raise_exception keyword argument that will trigger a 403 if the user doesn't have the appropriate permission.

like image 84
Fush Avatar answered Sep 20 '22 18:09

Fush