Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #15688 - Generic views should provide a HEAD implementation

Thanks to j4mie for the report and patch!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16095 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f4c808b7f50d6906d96593626ccdd016b0b1b96b 1 parent 065e6b6
@spookylukey spookylukey authored
View
2  django/views/generic/base.py
@@ -44,6 +44,8 @@ def as_view(cls, **initkwargs):
def view(request, *args, **kwargs):
self = cls(**initkwargs)
+ if hasattr(self, 'get') and not hasattr(self, 'head'):
+ self.head = self.get
return self.dispatch(request, *args, **kwargs)
# take name and docstring from class
View
15 tests/regressiontests/generic_views/base.py
@@ -101,6 +101,14 @@ def test_get_only(self):
self.rf.get('/', REQUEST_METHOD='FAKE')
).status_code, 405)
+ def test_get_and_head(self):
+ """
+ Test a view which supplies a GET method also responds correctly to HEAD
+ """
+ self._assert_simple(SimpleView.as_view()(self.rf.get('/')))
+ response = SimpleView.as_view()(self.rf.head('/'))
+ self.assertEqual(response.status_code, 200)
+
def test_get_and_post(self):
"""
Test a view which only allows both GET and POST.
@@ -167,6 +175,13 @@ def test_get(self):
"""
self._assert_about(AboutTemplateView.as_view()(self.rf.get('/about/')))
+ def test_head(self):
+ """
+ Test a TemplateView responds correctly to HEAD
+ """
+ response = AboutTemplateView.as_view()(self.rf.head('/about/'))
+ self.assertEqual(response.status_code, 200)
+
def test_get_template_attribute(self):
"""
Test a view that renders a template on GET with the template name as
Please sign in to comment.
Something went wrong with that request. Please try again.