summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Poulailleau <vpoulailleau@gmail.com>2018-01-15 13:03:13 +0100
committerTim Graham <timograham@gmail.com>2018-01-17 10:58:05 -0500
commitfcd431c6c3159a753f1cc0658cc4b25803ffccc1 (patch)
tree2f724d93bf418ba6f462f57577a55d11d34146e2
parent27557a7a99ab1ad032c699dc01e114a5e6504b0a (diff)
Improved generic detail view error message for when pk or slug is missing.
-rw-r--r--django/views/generic/detail.py7
-rw-r--r--tests/generic_views/test_dates.py6
2 files changed, 9 insertions, 4 deletions
diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py
index 6d5b8a3f5c..1922114598 100644
--- a/django/views/generic/detail.py
+++ b/django/views/generic/detail.py
@@ -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
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py
index 054ec7d223..6a18e090e6 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -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):