Fixed #26911 -- Removed NoReverseMatch silencing in RedirectView.
This commit is contained in:
parent
2863e79a5c
commit
fede65260a
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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/'))
|
||||
|
|
Loading…
Reference in New Issue