Skip to content

Commit 0546794

Browse files
keimlinkapollo13
authored andcommitted
Fixed django#19230 -- Extended the handler403 documentation.
Added a paragraph on how to use the PermissionDenied exception to create a 403 response and use handler403.
1 parent 095eca8 commit 0546794

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/topics/http/views.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ This view loads and renders the template ``403.html`` in your root template
209209
directory, or if this file does not exist, instead serves the text
210210
"403 Forbidden", as per :rfc:`2616` (the HTTP 1.1 Specification).
211211

212+
``django.views.defaults.permission_denied`` is triggered by a
213+
:exc:`~django.core.exceptions.PermissionDenied` exception. To deny access in a
214+
view you can use code like this::
215+
216+
from django.core.exceptions import PermissionDenied
217+
218+
def edit(request, pk):
219+
if not request.user.is_staff:
220+
raise PermissionDenied
221+
# ...
222+
212223
It is possible to override ``django.views.defaults.permission_denied`` in the
213224
same way you can for the 404 and 500 views by specifying a ``handler403`` in
214225
your URLconf::

0 commit comments

Comments
 (0)