#32681: 'subtitle' missing from admin context on index page
---------------------------------+--------------------------------------
     Reporter:  Zain Patel       |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  contrib.admin    |                  Version:  3.2
     Severity:  Normal           |               Resolution:
     Keywords:  admin, template  |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Description changed by Zain Patel:

Old description:

> This looks like a bug introduced in Django 3.2 with the introduction of a
> new variable introduced in the base templates
> (`django/contrib/admin/templates/base_site.html`) named `subtitle.` This
> variable is passed in most places within the admin site, e.g in
> django/contrib/admin/options.py
>
> Loading the admin index page with log-level debug shows the following
> exception/stack trace (that admittedly does not affect anything
> functional - simply clutters the logs):
>

> {{{
> Exception while resolving variable 'subtitle' in template
> 'admin/index.html'.
> Traceback (most recent call last):
>   File "...lib/python3.7/site-packages/django/template/base.py", line
> 829, in _resolve_lookup
>     current = current[bit]
>   File "...lib/python3.7/site-packages/django/template/context.py", line
> 83, in __getitem__
>     raise KeyError(key)
> KeyError: 'subtitle'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "...lib/python3.7/site-packages/django/template/base.py", line
> 835, in _resolve_lookup
>     if isinstance(current, BaseContext) and getattr(type(current), bit):
> AttributeError: type object 'RequestContext' has no attribute 'subtitle'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "...lib/python3.7/site-packages/django/template/base.py", line
> 843, in _resolve_lookup
>     current = current[int(bit)]
> ValueError: invalid literal for int() with base 10: 'subtitle'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "...lib/python3.7/site-packages/django/template/base.py", line
> 850, in _resolve_lookup
>     (bit, current))  # missing attribute
> django.template.base.VariableDoesNotExist: Failed lookup for key
> [subtitle] in
> }}}
>
> I believe this can be fixed by providing `subtitle: None` in the
> AdminSite.each_context` method to default it to that. I am happy to
> create a PR for this.

New description:

 This looks like a bug introduced in Django 3.2 with the introduction of a
 new variable introduced in the base templates
 (`django/contrib/admin/templates/base_site.html`) named `subtitle.` This
 variable is passed in most places within the admin site, e.g in
 django/contrib/admin/options.py

 Loading the admin index page with log-level debug shows the following
 exception/stack trace (that admittedly does not affect anything functional
 - simply clutters the logs):


 {{{
 Exception while resolving variable 'subtitle' in template
 'admin/index.html'.
 Traceback (most recent call last):
   File "...lib/python3.7/site-packages/django/template/base.py", line 829,
 in _resolve_lookup
     current = current[bit]
   File "...lib/python3.7/site-packages/django/template/context.py", line
 83, in __getitem__
     raise KeyError(key)
 KeyError: 'subtitle'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "...lib/python3.7/site-packages/django/template/base.py", line 835,
 in _resolve_lookup
     if isinstance(current, BaseContext) and getattr(type(current), bit):
 AttributeError: type object 'RequestContext' has no attribute 'subtitle'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "...lib/python3.7/site-packages/django/template/base.py", line 843,
 in _resolve_lookup
     current = current[int(bit)]
 ValueError: invalid literal for int() with base 10: 'subtitle'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "...lib/python3.7/site-packages/django/template/base.py", line 850,
 in _resolve_lookup
     (bit, current))  # missing attribute
 django.template.base.VariableDoesNotExist: Failed lookup for key
 [subtitle] in
 }}}

 I believe this can be fixed by providing `subtitle: None` in the
 AdminSite.each_context` method to default it to that. I am happy to create
 a PR for this.

 On second though - instead of hardcoding `subtitle` to None - potentially
 it should be a customisable option in the AdminSite itself, so:

 class MySite(AdminSite):
   site_header = "blah"
   subtitle = "my subtitle"

 ?

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32681#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.9216efcf15d94ad3bbf1c399376a6096%40djangoproject.com.

Reply via email to