Ticket #15668: 15668.2.patch

File 15668.2.patch, 1.8 KB (added by Jamie Matthews, 14 years ago)
  • django/views/generic/base.py

    diff --git a/django/views/generic/base.py b/django/views/generic/base.py
    index d732af5..760b1fe 100644
    a b class View(object):  
    4444
    4545        def view(request, *args, **kwargs):
    4646            self = cls(**initkwargs)
     47            if hasattr(self, 'get') and not hasattr(self, 'head'):
     48                self.head = self.get
    4749            return self.dispatch(request, *args, **kwargs)
    4850
    4951        # take name and docstring from class
  • tests/regressiontests/generic_views/base.py

    diff --git a/tests/regressiontests/generic_views/base.py b/tests/regressiontests/generic_views/base.py
    index e20932b..d97a90b 100644
    a b class ViewTest(unittest.TestCase):  
    101101            self.rf.get('/', REQUEST_METHOD='FAKE')
    102102        ).status_code, 405)
    103103
     104    def test_get_and_head(self):
     105        """
     106        Test a view which supplies a GET method also responds correctly to HEAD
     107        """
     108        self._assert_simple(SimpleView.as_view()(self.rf.get('/')))
     109        response = SimpleView.as_view()(self.rf.head('/'))
     110        self.assertEqual(response.status_code, 200)
     111
    104112    def test_get_and_post(self):
    105113        """
    106114        Test a view which only allows both GET and POST.
    class TemplateViewTest(TestCase):  
    167175        """
    168176        self._assert_about(AboutTemplateView.as_view()(self.rf.get('/about/')))
    169177
     178    def test_head(self):
     179        """
     180        Test a TemplateView responds correctly to HEAD
     181        """
     182        response = AboutTemplateView.as_view()(self.rf.head('/about/'))
     183        self.assertEqual(response.status_code, 200)
     184
    170185    def test_get_template_attribute(self):
    171186        """
    172187        Test a view that renders a template on GET with the template name as
Back to Top