Skip to content
Browse files

Fixed #17228 -- params context variable is inconsistent

Remove the params variable from the context and just put the variables
in directly.

This had not been committed previously as the original pattern was used
in the functional generic views and we wanted consistency between them,
but django.views.generic.simple.direct_to_template is now gone so we can
do it 'right'.
  • Loading branch information...
1 parent 212b982 commit f04bb6d798b07aa5e7c1d99d700fa6ddc7d39e62 @mjtamlyn mjtamlyn committed with andrewgodwin
6 django/views/generic/
@@ -142,11 +142,11 @@ def get_template_names(self):
class TemplateView(TemplateResponseMixin, ContextMixin, View):
- A view that renders a template. This view is different from all the others
- insofar as it also passes ``kwargs`` as ``params`` to the template context.
+ A view that renders a template. This view will also pass into the context
+ any keyword arguments passed by the url conf.
def get(self, request, *args, **kwargs):
- context = self.get_context_data(params=kwargs)
+ context = self.get_context_data(**kwargs)
return self.render_to_response(context)
8 docs/releases/1.5.txt
@@ -144,6 +144,14 @@ year|date:"Y" }}``.
``next_year`` and ``previous_year`` were also added in the context. They are
calculated according to ``allow_empty`` and ``allow_future``.
+Context in TemplateView
+For consistency with the design of the other generic views,
+:class:`~django.views.generic.base.TemplateView` no longer passes a ``params``
+dictionary into the context, instead passing the variables from the URLconf
+directly into the context.
OPTIONS, PUT and DELETE requests in the test client
4 tests/regressiontests/generic_views/
@@ -275,7 +275,7 @@ def test_template_params(self):
response = self.client.get('/template/simple/bar/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.context['params'], {'foo': 'bar'})
+ self.assertEqual(response.context['foo'], 'bar')
self.assertTrue(isinstance(response.context['view'], View))
def test_extra_template_params(self):
@@ -284,7 +284,7 @@ def test_extra_template_params(self):
response = self.client.get('/template/custom/bar/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.context['params'], {'foo': 'bar'})
+ self.assertEqual(response.context['foo'], 'bar')
self.assertEqual(response.context['key'], 'value')
self.assertTrue(isinstance(response.context['view'], View))

0 comments on commit f04bb6d

Please sign in to comment.
Something went wrong with that request. Please try again.