diff options
| author | Alasdair Nicol <alasdair@thenicols.net> | 2019-04-04 00:17:25 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-04-25 11:38:35 +0200 |
| commit | 3c3df7db8e5ce7882d6a8379fc2d0f82330114f1 (patch) | |
| tree | fa3a3533bd412af7980ee2dc3586ba8fc1914def /django/urls/resolvers.py | |
| parent | f24cf51661af21cfe2d90d7cba6557c56778ef20 (diff) | |
[2.2.x] Fixed #30318 -- Added check for importability of arguments of custom error handler views.
Thanks to Jon on Stack Overflow for reporting the issue.
Backport of a5accc0368c6575b55976c06af36ed399c85c781 from master
Diffstat (limited to 'django/urls/resolvers.py')
| -rw-r--r-- | django/urls/resolvers.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/django/urls/resolvers.py b/django/urls/resolvers.py index 8f59313c93..9d3379a821 100644 --- a/django/urls/resolvers.py +++ b/django/urls/resolvers.py @@ -15,7 +15,7 @@ from urllib.parse import quote from django.conf import settings from django.core.checks import Error, Warning from django.core.checks.urls import check_resolver -from django.core.exceptions import ImproperlyConfigured +from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist from django.utils.datastructures import MultiValueDict from django.utils.functional import cached_property from django.utils.http import RFC3986_SUBDELIMS, escape_leading_slashes @@ -405,7 +405,15 @@ class URLResolver: # All handlers take (request, exception) arguments except handler500 # which takes (request). for status_code, num_parameters in [(400, 2), (403, 2), (404, 2), (500, 1)]: - handler, param_dict = self.resolve_error_handler(status_code) + try: + handler, param_dict = self.resolve_error_handler(status_code) + except (ImportError, ViewDoesNotExist) as e: + path = getattr(self.urlconf_module, 'handler%s' % status_code) + msg = ( + "The custom handler{status_code} view '{path}' could not be imported." + ).format(status_code=status_code, path=path) + messages.append(Error(msg, hint=str(e), id='urls.E008')) + continue signature = inspect.signature(handler) args = [None] * num_parameters try: |
