diff --git a/django/views/generic/base.py b/django/views/generic/base.py
index d732af5..760b1fe 100644
|
a
|
b
|
class View(object):
|
| 44 | 44 | |
| 45 | 45 | def view(request, *args, **kwargs): |
| 46 | 46 | self = cls(**initkwargs) |
| | 47 | if hasattr(self, 'get') and not hasattr(self, 'head'): |
| | 48 | self.head = self.get |
| 47 | 49 | return self.dispatch(request, *args, **kwargs) |
| 48 | 50 | |
| 49 | 51 | # take name and docstring from class |
diff --git a/tests/regressiontests/generic_views/base.py b/tests/regressiontests/generic_views/base.py
index e20932b..9a685ef 100644
|
a
|
b
|
class InstanceView(View):
|
| 56 | 56 | return self |
| 57 | 57 | |
| 58 | 58 | |
| 59 | | class ViewTest(unittest.TestCase): |
| | 59 | class ViewTest(TestCase): |
| | 60 | urls = 'regressiontests.generic_views.urls' |
| | 61 | |
| 60 | 62 | rf = RequestFactory() |
| 61 | 63 | |
| 62 | 64 | def _assert_simple(self, response): |
| … |
… |
class ViewTest(unittest.TestCase):
|
| 101 | 103 | self.rf.get('/', REQUEST_METHOD='FAKE') |
| 102 | 104 | ).status_code, 405) |
| 103 | 105 | |
| | 106 | def test_get_and_head(self): |
| | 107 | """ |
| | 108 | Test a view which supplies a GET method also responds correctly to HEAD. |
| | 109 | Need to use TestClient rather than RequestFactory here because the content |
| | 110 | of the response is stripped by the conditional_content_removal function in |
| | 111 | django.http.utils, which is called by BaseHandler, so we need to invoke |
| | 112 | the complete request/response cycle. |
| | 113 | """ |
| | 114 | response = self.client.head('/simple/') |
| | 115 | self.assertEqual(response.status_code, 200) |
| | 116 | self.assertEqual(response.content, '') |
| | 117 | |
| 104 | 118 | def test_get_and_post(self): |
| 105 | 119 | """ |
| 106 | 120 | Test a view which only allows both GET and POST. |
| … |
… |
class TemplateViewTest(TestCase):
|
| 167 | 181 | """ |
| 168 | 182 | self._assert_about(AboutTemplateView.as_view()(self.rf.get('/about/'))) |
| 169 | 183 | |
| | 184 | def test_head(self): |
| | 185 | """ |
| | 186 | Test a TemplateView responds correctly to HEAD |
| | 187 | """ |
| | 188 | response = self.client.head('/template/simple/bar/') |
| | 189 | self.assertEqual(response.status_code, 200) |
| | 190 | self.assertEqual(response.content, '') |
| | 191 | |
| 170 | 192 | def test_get_template_attribute(self): |
| 171 | 193 | """ |
| 172 | 194 | Test a view that renders a template on GET with the template name as |
diff --git a/tests/regressiontests/generic_views/urls.py b/tests/regressiontests/generic_views/urls.py
index c06b5d8..46dbc82 100644
|
a
|
b
|
from django.views.generic import TemplateView
|
| 3 | 3 | from django.views.decorators.cache import cache_page |
| 4 | 4 | |
| 5 | 5 | import views |
| | 6 | import base |
| 6 | 7 | |
| 7 | 8 | |
| 8 | 9 | urlpatterns = patterns('', |
| … |
… |
urlpatterns = patterns('',
|
| 10 | 11 | #(r'^about/login-required/$', |
| 11 | 12 | # views.DecoratedAboutView()), |
| 12 | 13 | |
| | 14 | # Base |
| | 15 | (r'^simple/$', |
| | 16 | base.SimpleView.as_view()), |
| | 17 | |
| 13 | 18 | # TemplateView |
| 14 | 19 | (r'^template/no_template/$', |
| 15 | 20 | TemplateView.as_view()), |