Opened 11 years ago

Closed 9 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

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

comment:1 by Kamu, 11 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Kamu, 11 years ago

Needs documentation: set
Version: 1.5

comment:3 by alasdair, 11 years ago

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

Last edited 11 years ago by alasdair (previous) (diff)

comment:4 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #24733 which has been fixed.

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