mirror of https://github.com/django/django.git
Improved generic detail view error message for when pk or slug is missing.
This commit is contained in:
parent
27557a7a99
commit
fcd431c6c3
|
@ -42,9 +42,10 @@ class SingleObjectMixin(ContextMixin):
|
|||
|
||||
# If none of those are defined, it's an error.
|
||||
if pk is None and slug is None:
|
||||
raise AttributeError("Generic detail view %s must be called with "
|
||||
"either an object pk or a slug."
|
||||
% self.__class__.__name__)
|
||||
raise AttributeError(
|
||||
"Generic detail view %s must be called with either an object "
|
||||
"pk or a slug in the URLconf." % self.__class__.__name__
|
||||
)
|
||||
|
||||
try:
|
||||
# Get the single item from the filtered queryset
|
||||
|
|
|
@ -695,7 +695,11 @@ class DateDetailViewTests(TestDataMixin, TestCase):
|
|||
self.assertEqual(res.context['exception'], 'Date out of range')
|
||||
|
||||
def test_invalid_url(self):
|
||||
with self.assertRaises(AttributeError):
|
||||
msg = (
|
||||
'Generic detail view BookDetail must be called with either an '
|
||||
'object pk or a slug in the URLconf.'
|
||||
)
|
||||
with self.assertRaisesMessage(AttributeError, msg):
|
||||
self.client.get("/dates/books/2008/oct/01/nopk/")
|
||||
|
||||
def test_get_object_custom_queryset(self):
|
||||
|
|
Loading…
Reference in New Issue