Opened 3 years ago

Closed 4 months 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 2 years ago by Kamu

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 2 years ago by Kamu

  • Needs documentation set
  • Version 1.5 deleted

comment:3 Changed 2 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 2 years ago by alasdair (next)

comment:4 Changed 4 months ago by timgraham

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #24733 which has been fixed.

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