diff --git a/django/views/generic/base.py b/django/views/generic/base.py index dc9137d3b7..f63c89ac52 100644 --- a/django/views/generic/base.py +++ b/django/views/generic/base.py @@ -7,7 +7,7 @@ from django.http import ( HttpResponsePermanentRedirect, HttpResponseRedirect, ) from django.template.response import TemplateResponse -from django.urls import NoReverseMatch, reverse +from django.urls import reverse from django.utils.decorators import classonlymethod logger = logging.getLogger('django.request') @@ -174,10 +174,7 @@ class RedirectView(View): if self.url: url = self.url % kwargs elif self.pattern_name: - try: - url = reverse(self.pattern_name, args=args, kwargs=kwargs) - except NoReverseMatch: - return None + url = reverse(self.pattern_name, args=args, kwargs=kwargs) else: return None diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index cd222dbba0..1c26193456 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -283,6 +283,9 @@ Miscellaneous instead of dotted Python path strings. Django favors callable references since they provide better performance and debugging experience. +* :class:`~django.views.generic.base.RedirectView` no longer silences + ``NoReverseMatch`` if the ``pattern_name`` doesn't exist. + .. _deprecated-features-2.0: Features deprecated in 2.0 diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py index 88c376dddc..f8061ca09d 100644 --- a/tests/generic_views/test_base.py +++ b/tests/generic_views/test_base.py @@ -407,11 +407,6 @@ class RedirectViewTest(SimpleTestCase): self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], '/detail/artist/1/') - def test_wrong_named_url_pattern(self): - "A wrong pattern name returns 410 GONE" - response = RedirectView.as_view(pattern_name='wrong.pattern_name')(self.rf.get('/foo/')) - self.assertEqual(response.status_code, 410) - def test_redirect_POST(self): "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.post('/foo/'))