From b09faa497ee5f7dfe9cd54515cf8d3828960d306 Mon Sep 17 00:00:00 2001 From: Dmitry Gladkov Date: Fri, 27 Jan 2017 23:13:40 +0200 Subject: [PATCH] Fixed #27748 -- Switched HTTP error handlers to reference callables instead of strings. --- django/conf/urls/__init__.py | 9 +++++---- docs/ref/urls.txt | 20 ++++---------------- docs/releases/2.0.txt | 4 ++++ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/django/conf/urls/__init__.py b/django/conf/urls/__init__.py index 47d6b310e2..bfb0961cfc 100644 --- a/django/conf/urls/__init__.py +++ b/django/conf/urls/__init__.py @@ -4,13 +4,14 @@ from django.core.exceptions import ImproperlyConfigured from django.urls import ( LocaleRegexURLResolver, RegexURLPattern, RegexURLResolver, ) +from django.views import defaults __all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'url'] -handler400 = 'django.views.defaults.bad_request' -handler403 = 'django.views.defaults.permission_denied' -handler404 = 'django.views.defaults.page_not_found' -handler500 = 'django.views.defaults.server_error' +handler400 = defaults.bad_request +handler403 = defaults.permission_denied +handler404 = defaults.page_not_found +handler500 = defaults.server_error def include(arg, namespace=None): diff --git a/docs/ref/urls.txt b/docs/ref/urls.txt index 505295ede4..c4ff8f7b90 100644 --- a/docs/ref/urls.txt +++ b/docs/ref/urls.txt @@ -90,13 +90,10 @@ A callable, or a string representing the full Python import path to the view that should be called if the HTTP client has sent a request that caused an error condition and a response with a status code of 400. -By default, this is ``'django.views.defaults.bad_request'``. If you +By default, this is :func:`django.views.defaults.bad_request`. If you implement a custom view, be sure it returns an :class:`~django.http.HttpResponseBadRequest`. -See the documentation about :ref:`the 400 (bad request) view -` for more information. - ``handler403`` ============== @@ -106,13 +103,10 @@ A callable, or a string representing the full Python import path to the view that should be called if the user doesn't have the permissions required to access a resource. -By default, this is ``'django.views.defaults.permission_denied'``. If you +By default, this is :func:`django.views.defaults.permission_denied`. If you implement a custom view, be sure it returns an :class:`~django.http.HttpResponseForbidden`. -See the documentation about :ref:`the 403 (HTTP Forbidden) view -` for more information. - ``handler404`` ============== @@ -121,13 +115,10 @@ See the documentation about :ref:`the 403 (HTTP Forbidden) view A callable, or a string representing the full Python import path to the view that should be called if none of the URL patterns match. -By default, this is ``'django.views.defaults.page_not_found'``. If you +By default, this is :func:`django.views.defaults.page_not_found`. If you implement a custom view, be sure it returns an :class:`~django.http.HttpResponseNotFound`. -See the documentation about :ref:`the 404 (HTTP Not Found) view -` for more information. - ``handler500`` ============== @@ -137,9 +128,6 @@ A callable, or a string representing the full Python import path to the view that should be called in case of server errors. Server errors happen when you have runtime errors in view code. -By default, this is ``'django.views.defaults.server_error'``. If you +By default, this is :func:`django.views.defaults.server_error`. If you implement a custom view, be sure it returns an :class:`~django.http.HttpResponseServerError`. - -See the documentation about :ref:`the 500 (HTTP Internal Server Error) view -` for more information. diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 519b7cd947..ca914118ca 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -217,6 +217,10 @@ Miscellaneous functionality since session authentication is unconditionally enabled in Django 1.10. +* The default HTTP error handlers (``handler404``, etc.) are now callables + instead of dotted Python path strings. Django favors callable references + since they provide better performance and debugging experience. + .. _deprecated-features-2.0: Features deprecated in 2.0