Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #15739 -- Added support to RedirectView for HEAD, OPTIONS, POST…

…, PUT and DELETE requests

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15992 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 62f37c69b075a5d11b5fddc6c59b4f4b418ba358 1 parent ae5f3e7
@freakboy3742 freakboy3742 authored
View
15 django/views/generic/base.py
@@ -161,3 +161,18 @@ def get(self, request, *args, **kwargs):
'request': self.request
})
return http.HttpResponseGone()
+
+ def head(self, request, *args, **kwargs):
+ return self.get(request, *args, **kwargs)
+
+ def post(self, request, *args, **kwargs):
+ return self.get(request, *args, **kwargs)
+
+ def options(self, request, *args, **kwargs):
+ return self.get(request, *args, **kwargs)
+
+ def delete(self, request, *args, **kwargs):
+ return self.get(request, *args, **kwargs)
+
+ def put(self, request, *args, **kwargs):
+ return self.get(request, *args, **kwargs)
View
30 tests/regressiontests/generic_views/base.py
@@ -261,3 +261,33 @@ def test_parameter_substitution(self):
response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/42/')
+
+ def test_redirect_POST(self):
+ "Default is a permanent redirect"
+ response = RedirectView.as_view(url='/bar/')(self.rf.post('/foo/'))
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response['Location'], '/bar/')
+
+ def test_redirect_HEAD(self):
+ "Default is a permanent redirect"
+ response = RedirectView.as_view(url='/bar/')(self.rf.head('/foo/'))
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response['Location'], '/bar/')
+
+ def test_redirect_OPTIONS(self):
+ "Default is a permanent redirect"
+ response = RedirectView.as_view(url='/bar/')(self.rf.options('/foo/'))
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response['Location'], '/bar/')
+
+ def test_redirect_PUT(self):
+ "Default is a permanent redirect"
+ response = RedirectView.as_view(url='/bar/')(self.rf.put('/foo/'))
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response['Location'], '/bar/')
+
+ def test_redirect_DELETE(self):
+ "Default is a permanent redirect"
+ response = RedirectView.as_view(url='/bar/')(self.rf.delete('/foo/'))
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response['Location'], '/bar/')
Please sign in to comment.
Something went wrong with that request. Please try again.