From f76c2312fe65661b715cc2f2c04975c1ccbd3e24 Mon Sep 17 00:00:00 2001
From: Vladimir Kryachko <vladimir.kryachko@etvnet.com>
Date: Wed, 14 Jul 2010 21:52:41 -0400
Subject: [PATCH] FIx
---
django/conf/urls/defaults.py | 1 +
django/core/handlers/base.py | 6 +++++-
django/core/urlresolvers.py | 3 +++
django/views/defaults.py | 4 ++++
4 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/django/conf/urls/defaults.py b/django/conf/urls/defaults.py
index 3ab8bab..82f226b 100644
a
|
b
|
__all__ = ['handler404', 'handler500', 'include', 'patterns', 'url']
|
5 | 5 | |
6 | 6 | handler404 = 'django.views.defaults.page_not_found' |
7 | 7 | handler500 = 'django.views.defaults.server_error' |
| 8 | handler403 = 'django.views.defaults.permission_denied' |
8 | 9 | |
9 | 10 | def include(arg, namespace=None, app_name=None): |
10 | 11 | if isinstance(arg, tuple): |
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
index b03c2fd..65f2fa4 100644
a
|
b
|
class BaseHandler(object):
|
131 | 131 | finally: |
132 | 132 | receivers = signals.got_request_exception.send(sender=self.__class__, request=request) |
133 | 133 | except exceptions.PermissionDenied: |
134 | | return http.HttpResponseForbidden('<h1>Permission denied</h1>') |
| 134 | try: |
| 135 | callback, param_dict = resolver.resolve403() |
| 136 | return callback(request, **param_dict) |
| 137 | except: |
| 138 | return http.HttpResponseForbidden('<h1>Permission denied</h1>') |
135 | 139 | except SystemExit: |
136 | 140 | # Allow sys.exit() to actually exit. See tickets #1023 and #4701 |
137 | 141 | raise |
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index cad57a5..4f7e07e 100644
a
|
b
|
class RegexURLResolver(object):
|
260 | 260 | |
261 | 261 | def resolve500(self): |
262 | 262 | return self._resolve_special('500') |
| 263 | |
| 264 | def resolve403(self): |
| 265 | return self._resolve_special('403') |
263 | 266 | |
264 | 267 | def reverse(self, lookup_view, *args, **kwargs): |
265 | 268 | if args and kwargs: |
diff --git a/django/views/defaults.py b/django/views/defaults.py
index 68b9ad6..1364f10 100644
a
|
b
|
def server_error(request, template_name='500.html'):
|
23 | 23 | t = loader.get_template(template_name) # You need to create a 500.html template. |
24 | 24 | return http.HttpResponseServerError(t.render(Context({}))) |
25 | 25 | |
| 26 | def permission_denied(request, template_name='403.html'): |
| 27 | t = loader.get_template(template_name) # You need to create a 403.html template. |
| 28 | return http.HttpResponseForbidden(t.render(Context({'request_path': request.path}))) |
| 29 | |
26 | 30 | def shortcut(request, content_type_id, object_id): |
27 | 31 | # TODO: Remove this in Django 2.0. |
28 | 32 | # This is a legacy view that depends on the contenttypes framework. |