I attempted to raise a 403 error if the user accesses a page he is not allowed to access. In my views.py
def staff_room(request): user = request.user role = School.objects.get(user=user) if not role.is_teacher: raise PermissionDenied("Get out of the staff room!") def library(request): user = request.user role = School.objects.get(user=user) if not role.is_librarian: raise PermissionDenied("Get out of the library!") In my 403.html, I want to retrieve the different messages thrown by the errors. Is there a way to do so? Something like {{ exception.message }} like say
{% extends 'base.html' %} You are not allowed to enter this room. {{ exception.message}}