Repository: django/django
File: django/views/debug.py (Python)

Code before:
    for urlpattern in tried or ():
        patterns = []
        for inner_pattern in urlpattern:
            wrapper = {"tried": inner_pattern}
            if isinstance(inner_pattern, URLResolver):
                wrapper["debug_key"] = "namespace"
                wrapper["debug_val"] = inner_pattern.namespace
            else:
                wrapper["debug_key"] = "name"
                wrapper["debug_val"] = inner_pattern.name
            patterns.append(wrapper)
        patterns_with_debug_info.append(patterns)

    urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
    if isinstance(urlconf, types.ModuleType):
        urlconf = urlconf.__name__

    with builtin_template_path("technical_404.html").open(encoding="utf-8") as fh:
        t = DEBUG_ENGINE.from_string(fh.read())
    reporter_filter = get_default_exception_reporter_filter()
    c = Context(
        {
            "urlconf": urlconf,
            "root_urlconf": settings.ROOT_URLCONF,
            "request_path": error_url,
            "urlpatterns": patterns_with_debug_info,
            "resolved": resolved,
            "reason": str(exception),
            "request": request,
            "settings": reporter_filter.get_safe_settings(),
            "raising_view_name": get_caller(request),
        }
    )
    return HttpResponseNotFound(t.render(c))


def default_urlconf(request):
    """Create an empty URLconf 404 error response."""
    with builtin_template_path("default_urlconf.html").open(encoding="utf-8") as fh:
        t = DEBUG_ENGINE.from_string(fh.read())
    c = Context(
        {
            "version": get_docs_version(),
        }
    )

    return HttpResponse(t.render(c))


Review comment (bug):
I don't know whether we need to be concerned or not but we could add `urlpatterns_debug` to the context and leave `urlpatterns` alone or make sure that the structure of `urlpatterns` is backwards compatible for if someone was overwriting the `technical_404.html` template

Code after:
    for urlpattern in tried or ():
        patterns = []
        for inner_pattern in urlpattern:
            wrapper = {"tried": inner_pattern}
            if isinstance(inner_pattern, URLResolver):
                wrapper["debug_key"] = "namespace"
                wrapper["debug_val"] = inner_pattern.namespace
            else:
                wrapper["debug_key"] = "name"
                wrapper["debug_val"] = inner_pattern.name
            patterns.append(wrapper)
        patterns_with_debug_info.append(patterns)

    urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
    if isinstance(urlconf, types.ModuleType):
        urlconf = urlconf.__name__

    with builtin_template_path("technical_404.html").open(encoding="utf-8") as fh:
        t = DEBUG_ENGINE.from_string(fh.read())
    reporter_filter = get_default_exception_reporter_filter()
    c = Context(
        {
            "urlconf": urlconf,
            "root_urlconf": settings.ROOT_URLCONF,
            "request_path": error_url,
            "urlpatterns": tried,  # Unused, left for compatibility.
            "urlpatterns_debug": patterns_with_debug_info,
            "resolved": resolved,
            "reason": str(exception),
            "request": request,
            "settings": reporter_filter.get_safe_settings(),
            "raising_view_name": get_caller(request),
        }
    )
    return HttpResponseNotFound(t.render(c))


def default_urlconf(request):
    """Create an empty URLconf 404 error response."""
    with builtin_template_path("default_urlconf.html").open(encoding="utf-8") as fh:
        t = DEBUG_ENGINE.from_string(fh.read())
    c = Context(
        {
            "version": get_docs_version(),
        }
    )

    return HttpResponse(t.render(c))