Code

Ticket #9847: base.3.diff

File base.3.diff, 2.8 KB (added by vkryachko, 4 years ago)
Line 
1From 22b9ea197751f2d36e99e8a47c5fbfcca7d66f53 Mon Sep 17 00:00:00 2001
2From: Vladimir Kryachko <vladimir.kryachko@etvnet.com>
3Date: Wed, 14 Jul 2010 21:52:41 -0400
4Subject: [PATCH] FIx
5
6
7diff --git a/django/conf/urls/defaults.py b/django/conf/urls/defaults.py
8index 3ab8bab..ecc79ba 100644
9--- a/django/conf/urls/defaults.py
10+++ b/django/conf/urls/defaults.py
11@@ -5,6 +5,7 @@ __all__ = ['handler404', 'handler500', 'include', 'patterns', 'url']
12 
13 handler404 = 'django.views.defaults.page_not_found'
14 handler500 = 'django.views.defaults.server_error'
15+handler403 = 'django.views.defaults.server_error'
16 
17 def include(arg, namespace=None, app_name=None):
18     if isinstance(arg, tuple):
19diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
20index b03c2fd..65f2fa4 100644
21--- a/django/core/handlers/base.py
22+++ b/django/core/handlers/base.py
23@@ -131,7 +131,11 @@ class BaseHandler(object):
24                         finally:
25                             receivers = signals.got_request_exception.send(sender=self.__class__, request=request)
26             except exceptions.PermissionDenied:
27-                return http.HttpResponseForbidden('<h1>Permission denied</h1>')
28+                try:
29+                    callback, param_dict = resolver.resolve403()
30+                    return callback(request, **param_dict)
31+                except:
32+                    return http.HttpResponseForbidden('<h1>Permission denied</h1>')
33             except SystemExit:
34                 # Allow sys.exit() to actually exit. See tickets #1023 and #4701
35                 raise
36diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
37index cad57a5..4f7e07e 100644
38--- a/django/core/urlresolvers.py
39+++ b/django/core/urlresolvers.py
40@@ -260,6 +260,9 @@ class RegexURLResolver(object):
41 
42     def resolve500(self):
43         return self._resolve_special('500')
44+   
45+    def resolve403(self):
46+        return self._resolve_special('403')
47 
48     def reverse(self, lookup_view, *args, **kwargs):
49         if args and kwargs:
50diff --git a/django/views/defaults.py b/django/views/defaults.py
51index 68b9ad6..1364f10 100644
52--- a/django/views/defaults.py
53+++ b/django/views/defaults.py
54@@ -23,6 +23,10 @@ def server_error(request, template_name='500.html'):
55     t = loader.get_template(template_name) # You need to create a 500.html template.
56     return http.HttpResponseServerError(t.render(Context({})))
57 
58+def permission_denied(request, template_name='403.html'):
59+    t = loader.get_template(template_name) # You need to create a 403.html template.
60+    return http.HttpResponseForbidden(t.render(Context({'request_path': request.path})))
61+
62 def shortcut(request, content_type_id, object_id):
63     # TODO: Remove this in Django 2.0.
64     # This is a legacy view that depends on the contenttypes framework.
65--
661.7.1
67