Opened 5 years ago

Closed 3 years ago

#20156 closed New feature (duplicate)

pass context info from PermissionDenied exception to handler403/django.views.defaults.permission_denied

Reported by: jc@… Owned by: nobody
Component: Core (Other) Version:
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Being able to raise PermissionDenied in a view and have django.view.defaults.permission_denied render a 403.html template is all well and good. But being able to pass context information via the exception to the template would make it possible to present customized messages to the user – for instance, explaining what action was forbidden and why, and how to rectify the situation.

As an example, suppose a view raised a PermissionDenied exception as follows:

raise PermissionDenied('not owner')

Then the corresponding 403.html could present a more detailed message like so:

{% with reason=except.args[0] %}
  {% if reason == 'not owner' %}
    <p>You may only edit entries that you own.</p>
  {% elif reason == 'not subscribed' %}
    <p>You may not edit entries if your subscription has lapsed.</p> 
  {% endif %}
{% endwith %}

Change History (4)

comment:1 Changed 5 years ago by Kamu

Triage Stage: UnreviewedAccepted

comment:2 Changed 5 years ago by Kamu

Needs documentation: set
Version: 1.5

comment:3 Changed 5 years ago by alasdair

A similar request for 404 requests #20803 was closed as won't fix (discussion on the pull request).

Version 0, edited 5 years ago by alasdair (next)

comment:4 Changed 3 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Duplicate of #24733 which has been fixed.

Note: See TracTickets for help on using tickets.
Back to Top