Loading django/views/generic/base.py +2 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ class ContextMixin(object): """ def get_context_data(self, **kwargs): if 'view' not in kwargs: kwargs['view'] = self return kwargs Loading docs/ref/class-based-views/mixins-simple.txt +14 −2 Original line number Diff line number Diff line Loading @@ -17,8 +17,20 @@ ContextMixin .. method:: get_context_data(**kwargs) Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. The template context of all class-based generic views include a ``view`` variable that points to the ``View`` instance. .. admonition:: Use ``alters_data`` where appropriate Note that having the view instance in the template context may expose potentially hazardous methods to template authors. To prevent methods like this from being called in the template, set ``alters_data=True`` on those methods. For more information, read the documentation on :ref:`rendering a template context <alters-data-description>`. TemplateResponseMixin --------------------- Loading docs/ref/templates/api.txt +2 −0 Original line number Diff line number Diff line Loading @@ -198,6 +198,8 @@ straight lookups. Here are some things to keep in mind: * A variable can only be called if it has no required arguments. Otherwise, the system will return an empty string. .. _alters-data-description: * Obviously, there can be side effects when calling some variables, and it'd be either foolish or a security hole to allow the template system to access them. Loading docs/releases/1.5.txt +6 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,12 @@ By passing ``False`` using this argument it is now possible to retreive the :class:`ContentType <django.contrib.contenttypes.models.ContentType>` associated with proxy models. New ``view`` variable in class-based views context ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In all :doc:`generic class-based views </topics/class-based-views/index>` (or any class-based view inheriting from ``ContextMixin``), the context dictionary contains a ``view`` variable that points to the ``View`` instance. Minor features ~~~~~~~~~~~~~~ Loading tests/regressiontests/generic_views/base.py +2 −0 Original line number Diff line number Diff line Loading @@ -276,6 +276,7 @@ class TemplateViewTest(TestCase): response = self.client.get('/template/simple/bar/') self.assertEqual(response.status_code, 200) self.assertEqual(response.context['params'], {'foo': 'bar'}) self.assertTrue(isinstance(response.context['view'], View)) def test_extra_template_params(self): """ Loading @@ -285,6 +286,7 @@ class TemplateViewTest(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.context['params'], {'foo': 'bar'}) self.assertEqual(response.context['key'], 'value') self.assertTrue(isinstance(response.context['view'], View)) def test_cached_views(self): """ Loading Loading
django/views/generic/base.py +2 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ class ContextMixin(object): """ def get_context_data(self, **kwargs): if 'view' not in kwargs: kwargs['view'] = self return kwargs Loading
docs/ref/class-based-views/mixins-simple.txt +14 −2 Original line number Diff line number Diff line Loading @@ -17,8 +17,20 @@ ContextMixin .. method:: get_context_data(**kwargs) Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. The template context of all class-based generic views include a ``view`` variable that points to the ``View`` instance. .. admonition:: Use ``alters_data`` where appropriate Note that having the view instance in the template context may expose potentially hazardous methods to template authors. To prevent methods like this from being called in the template, set ``alters_data=True`` on those methods. For more information, read the documentation on :ref:`rendering a template context <alters-data-description>`. TemplateResponseMixin --------------------- Loading
docs/ref/templates/api.txt +2 −0 Original line number Diff line number Diff line Loading @@ -198,6 +198,8 @@ straight lookups. Here are some things to keep in mind: * A variable can only be called if it has no required arguments. Otherwise, the system will return an empty string. .. _alters-data-description: * Obviously, there can be side effects when calling some variables, and it'd be either foolish or a security hole to allow the template system to access them. Loading
docs/releases/1.5.txt +6 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,12 @@ By passing ``False`` using this argument it is now possible to retreive the :class:`ContentType <django.contrib.contenttypes.models.ContentType>` associated with proxy models. New ``view`` variable in class-based views context ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In all :doc:`generic class-based views </topics/class-based-views/index>` (or any class-based view inheriting from ``ContextMixin``), the context dictionary contains a ``view`` variable that points to the ``View`` instance. Minor features ~~~~~~~~~~~~~~ Loading
tests/regressiontests/generic_views/base.py +2 −0 Original line number Diff line number Diff line Loading @@ -276,6 +276,7 @@ class TemplateViewTest(TestCase): response = self.client.get('/template/simple/bar/') self.assertEqual(response.status_code, 200) self.assertEqual(response.context['params'], {'foo': 'bar'}) self.assertTrue(isinstance(response.context['view'], View)) def test_extra_template_params(self): """ Loading @@ -285,6 +286,7 @@ class TemplateViewTest(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.context['params'], {'foo': 'bar'}) self.assertEqual(response.context['key'], 'value') self.assertTrue(isinstance(response.context['view'], View)) def test_cached_views(self): """ Loading