Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20478 – Added support for HTTP PATCH method in generic views.

  • Loading branch information...
commit ee8b810b977572e39dc6acf4d13cc5e05f4d65ee 1 parent 0e51d8e
@KrzysiekJ KrzysiekJ authored
View
5 django/views/generic/base.py
@@ -30,7 +30,7 @@ class View(object):
dispatch-by-method and simple sanity checking.
"""
- http_method_names = ['get', 'post', 'put', 'delete', 'head', 'options', 'trace']
+ http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
def __init__(self, **kwargs):
"""
@@ -206,3 +206,6 @@ def delete(self, request, *args, **kwargs):
def put(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
+
+ def patch(self, request, *args, **kwargs):
+ return self.get(request, *args, **kwargs)
View
2  docs/ref/class-based-views/base.txt
@@ -55,7 +55,7 @@ View
Default::
- ['get', 'post', 'put', 'delete', 'head', 'options', 'trace']
+ ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
**Methods**
View
3  docs/releases/1.6.txt
@@ -258,6 +258,9 @@ Minor features
methods returning the first or last object matching the filters. Returns
``None`` if there are no objects matching.
+* :class:`~django.views.generic.base.View` and
+ :class:`~django.views.generic.base.RedirectView` now support HTTP PATCH method.
+
Backwards incompatible changes in 1.6
=====================================
View
6 tests/generic_views/test_base.py
@@ -384,6 +384,12 @@ def test_redirect_PUT(self):
self.assertEqual(response.status_code, 301)
self.assertEqual(response.url, '/bar/')
+ def test_redirect_PATCH(self):
+ "Default is a permanent redirect"
+ response = RedirectView.as_view(url='/bar/')(self.rf.patch('/foo/'))
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response.url, '/bar/')
+
def test_redirect_DELETE(self):
"Default is a permanent redirect"
response = RedirectView.as_view(url='/bar/')(self.rf.delete('/foo/'))
Please sign in to comment.
Something went wrong with that request. Please try again.