Opened 2 years ago

Last modified 21 months ago

#20156 new New feature

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

Description

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 (3)

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 23 months ago by Kamu

  • Needs documentation set
  • Version 1.5 deleted

comment:3 Changed 21 months ago by alasdair

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

Version 0, edited 21 months ago by alasdair (next)
Note: See TracTickets for help on using tickets.
Back to Top