I use django PermissionDeniedfor rendering 403.htmlwhen the user is not allowed access to any page.
There are many different types of pages, for example Product page, User Page, User Contact information, Owner Information.
I would like to add a custom post with PermissionDeniedthat would definitely tell the user why he cannot view this page. I would like to add the following dynamic post to 403.html.
You have are trying to `View a Product (id:3094384)` while having a `Trail` account. You are not authorized to view this product.
and
You have are trying to `View a Customer (id:48)` which is Private. You are not authorized to view this User.
etc.
here is my code
elif role.id == Project.ROLE_SALES and not project.sales_person_id == user_id:
raise PermissionDenied
HTML
<body class="error-page">
<section>
<div class="error403">
<h1>403</h1>
</div>
<p class="description">Oops! Request forbidden...</p>
<p>Sorry, it appears the page you were looking for is forbidden and not accessible. If the problem persists, please
contact web Administrator.</p>
# HERE I WANT TO SHOW DYNAMIC MESSAGE.
<a href="{{ request.META.HTTP_REFERER }}" class="btn btn-danger403 btn-primary btn-large" >
Go Back </a>
{{ except }}
</section>
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.js' %}"></script>
</body>
Opportunity
raise PermissionDenied("Custom message")
or
Pass the context to PermissionDenied?
Suggestions.
source
share