MCPcopy
hub / github.com/django/django / permission_denied

Function permission_denied

django/views/defaults.py:126–150  ·  view source on GitHub ↗

Permission denied (403) handler. Templates: :template:`403.html` Context: exception The message from the exception which triggered the 403 (if one was supplied). If the template does not exist, an Http403 response containing the text "403 Forbid

(request, exception, template_name=ERROR_403_TEMPLATE_NAME)

Source from the content-addressed store, hash-verified

124
125@requires_csrf_token
126def permission_denied(request, exception, template_name=ERROR_403_TEMPLATE_NAME):
127 """
128 Permission denied (403) handler.
129
130 Templates: :template:`403.html`
131 Context:
132 exception
133 The message from the exception which triggered the 403 (if one was
134 supplied).
135
136 If the template does not exist, an Http403 response containing the text
137 "403 Forbidden" (as per RFC 9110 Section 15.5.4) will be returned.
138 """
139 try:
140 template = loader.get_template(template_name)
141 except TemplateDoesNotExist:
142 if template_name != ERROR_403_TEMPLATE_NAME:
143 # Reraise if it's a missing custom template.
144 raise
145 return HttpResponseForbidden(
146 ERROR_PAGE_TEMPLATE % {"title": "403 Forbidden", "details": ""},
147 )
148 return HttpResponseForbidden(
149 template.render(request=request, context={"exception": str(exception)})
150 )

Callers 2

test_error_pagesMethod · 0.90

Calls 3

get_templateMethod · 0.45
renderMethod · 0.45

Tested by 2

test_error_pagesMethod · 0.72