About Forbidden Access
In a Django view, when a user does not have permission to modify an object, raise the PermissionDenied
exception:
from django.core.exceptions import PermissionDenied
raise PermissionDenied
You can customize its output in the template 403.html
.
If you want a custom content for that specific error message, return HttpResponseForbidden()
instead:
from django.http import HttpResponseForbidden
return HttpResponseForbidden(content)
Tips and Tricks User Experience Django 4.2 Django 3.2 Django 2.2
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.