#36861 closed Bug (duplicate)

technical_404.html crashes on urlpatterns with include()

Reported by: Christian Bahls Owned by:
Component: Error reporting Version: 6.0
Severity: Normal Keywords:
Cc: Christian Bahls Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

technical_404.html crashes on urlpatterns with include()

Summary

The debug 404 page (technical_404.html) crashes with an AttributeError when urlpatterns contains URLResolver objects created via include().

Description

The template iterates over URL patterns and accesses .name:

{% if forloop.last and pat.name %}[name='{{ pat.name }}']{% endif %}

This fails because .name only exists on URLPattern, not URLResolver. The {% if %} guard does not prevent the crash because Django's template engine evaluates pat.name before checking the conditional.

Exception

AttributeError: 'URLResolver' object has no attribute 'name'

Reproduce

  1. Configure urlpatterns with include() without namespace:
    urlpatterns = [
        path("app/", include("myapp.urls")),
    ]
    
  2. Set DEBUG=True
  3. Request any non-existent URL
  4. Debug 404 page crashes instead of rendering

Fix

PR: https://github.com/django/django/pull/20533

Change History (2)

comment:1 by Christian Bahls, 85 minutes ago

i run django 6.0.1 from PyPI in a docker and it crashes
please consider a backport

comment:2 by Jacob Walls, 81 minutes ago

Has patch: unset
Resolution: duplicate
Status: newclosed
UI/UX: unset

Duplicate of #26886, this behavior didn't change recently. Also, it doesn't crash, it just logs this noisy traceback.

Note: See TracTickets for help on using tickets.
Back to Top