Skip to content

Commit

Permalink
Refs #26007 -- Improved the ImproperlyConfigured error message for Si…
Browse files Browse the repository at this point in the history
…ngleObjectTemplateResponseMixin.get_template_names().
  • Loading branch information
nanorepublica authored and sarahboyce committed Dec 18, 2024
1 parent 0fc6d53 commit 3ee4c6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion django/views/generic/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ def get_template_names(self):
# If we still haven't managed to find any template names, we should
# re-raise the ImproperlyConfigured to alert the user.
if not names:
raise
raise ImproperlyConfigured(
"SingleObjectTemplateResponseMixin requires a definition "
"of 'template_name', 'template_name_field', or 'model'; "
"or an implementation of 'get_template_names()'."
)

return names

Expand Down
5 changes: 3 additions & 2 deletions tests/generic_views/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,9 @@ def test_template_mixin_without_template(self):
"""
view = views.TemplateResponseWithoutTemplate()
msg = (
"TemplateResponseMixin requires either a definition of "
"'template_name' or an implementation of 'get_template_names()'"
"SingleObjectTemplateResponseMixin requires a definition "
"of 'template_name', 'template_name_field', or 'model'; "
"or an implementation of 'get_template_names()'."
)
with self.assertRaisesMessage(ImproperlyConfigured, msg):
view.get_template_names()

0 comments on commit 3ee4c6a

Please sign in to comment.