#36861: technical_404.html crashes on urlpatterns with include()
-------------------------------------+-------------------------------------
Reporter: approximated- | Type: Bug
intelligence | Component: Error
Status: new | reporting
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
= 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`:
{{{#!django
{% 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:
{{{#!python
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
--
Ticket URL: <
https://code.djangoproject.com/ticket/36861>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.