MCPcopy
hub / github.com/django/django / check_custom_error_handlers

Function check_custom_error_handlers

django/core/checks/urls.py:123–158  ·  view source on GitHub ↗
(app_configs, **kwargs)

Source from the content-addressed store, hash-verified

121
122@register(Tags.urls)
123def check_custom_error_handlers(app_configs, **kwargs):
124 if not getattr(settings, "ROOT_URLCONF", None):
125 return []
126
127 from django.urls import get_resolver
128
129 resolver = get_resolver()
130
131 errors = []
132 # All handlers take (request, exception) arguments except handler500
133 # which takes (request).
134 for status_code, num_parameters in [(400, 2), (403, 2), (404, 2), (500, 1)]:
135 try:
136 handler = resolver.resolve_error_handler(status_code)
137 except (ImportError, ViewDoesNotExist) as e:
138 path = getattr(resolver.urlconf_module, "handler%s" % status_code)
139 msg = (
140 "The custom handler{status_code} view '{path}' could not be "
141 "imported."
142 ).format(status_code=status_code, path=path)
143 errors.append(Error(msg, hint=str(e), id="urls.E008"))
144 continue
145 args = [None] * num_parameters
146 try:
147 signature(handler).bind(*args)
148 except TypeError:
149 msg = (
150 "The custom handler{status_code} view '{path}' does not "
151 "take the correct number of arguments ({args})."
152 ).format(
153 status_code=status_code,
154 path=handler.__module__ + "." + handler.__qualname__,
155 args="request, exception" if num_parameters == 2 else "request",
156 )
157 errors.append(Error(msg, id="urls.E007"))
158 return errors

Calls 6

get_resolverFunction · 0.90
signatureFunction · 0.90
resolve_error_handlerMethod · 0.80
ErrorClass · 0.70
formatMethod · 0.45
appendMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…