|
@@ -1,10 +1,12 @@
|
|
|
from django import http
|
|
|
+from django.template import (Context, RequestContext,
|
|
|
+ loader, TemplateDoesNotExist)
|
|
|
from django.views.decorators.csrf import requires_csrf_token
|
|
|
-from django.template import Context, RequestContext, loader
|
|
|
|
|
|
|
|
|
-# This can be called when CsrfViewMiddleware.process_view has not run, therefore
|
|
|
-# need @requires_csrf_token in case the template needs {% csrf_token %}.
|
|
|
+# This can be called when CsrfViewMiddleware.process_view has not run,
|
|
|
+# therefore need @requires_csrf_token in case the template needs
|
|
|
+# {% csrf_token %}.
|
|
|
@requires_csrf_token
|
|
|
def page_not_found(request, template_name='404.html'):
|
|
|
"""
|
|
@@ -31,6 +33,27 @@ def server_error(request, template_name='500.html'):
|
|
|
return http.HttpResponseServerError(t.render(Context({})))
|
|
|
|
|
|
|
|
|
+# This can be called when CsrfViewMiddleware.process_view has not run,
|
|
|
+# therefore need @requires_csrf_token in case the template needs
|
|
|
+# {% csrf_token %}.
|
|
|
+@requires_csrf_token
|
|
|
+def permission_denied(request, template_name='403.html'):
|
|
|
+ """
|
|
|
+ Permission denied (403) handler.
|
|
|
+
|
|
|
+ Templates: `403.html`
|
|
|
+ Context: None
|
|
|
+
|
|
|
+ If the template does not exist, an Http403 response containing the text
|
|
|
+ "403 Forbidden" (as per RFC 2616) will be returned.
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ template = loader.get_template(template_name)
|
|
|
+ except TemplateDoesNotExist:
|
|
|
+ return http.HttpResponseForbidden('<h1>403 Forbidden</h1>')
|
|
|
+ return http.HttpResponseForbidden(template.render(RequestContext(request)))
|
|
|
+
|
|
|
+
|
|
|
def shortcut(request, content_type_id, object_id):
|
|
|
# TODO: Remove this in Django 2.0.
|
|
|
# This is a legacy view that depends on the contenttypes framework.
|