Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit f04bb6d798b07aa5e7c1d99d700fa6ddc7d39e62 1 parent 212b982
Marc Tamlyn authored August 18, 2012 andrewgodwin committed August 18, 2012
6  django/views/generic/base.py
@@ -142,11 +142,11 @@ def get_template_names(self):
142 142
 
143 143
 class TemplateView(TemplateResponseMixin, ContextMixin, View):
144 144
     """
145  
-    A view that renders a template.  This view is different from all the others
146  
-    insofar as it also passes ``kwargs`` as ``params`` to the template context.
  145
+    A view that renders a template.  This view will also pass into the context
  146
+    any keyword arguments passed by the url conf.
147 147
     """
148 148
     def get(self, request, *args, **kwargs):
149  
-        context = self.get_context_data(params=kwargs)
  149
+        context = self.get_context_data(**kwargs)
150 150
         return self.render_to_response(context)
151 151
 
152 152
 
8  docs/releases/1.5.txt
@@ -144,6 +144,14 @@ year|date:"Y" }}``.
144 144
 ``next_year`` and ``previous_year`` were also added in the context. They are
145 145
 calculated according to ``allow_empty`` and ``allow_future``.
146 146
 
  147
+Context in TemplateView
  148
+~~~~~~~~~~~~~~~~~~~~~~~
  149
+
  150
+For consistency with the design of the other generic views,
  151
+:class:`~django.views.generic.base.TemplateView` no longer passes a ``params``
  152
+dictionary into the context, instead passing the variables from the URLconf
  153
+directly into the context.
  154
+
147 155
 OPTIONS, PUT and DELETE requests in the test client
148 156
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149 157
 
4  tests/regressiontests/generic_views/base.py
@@ -275,7 +275,7 @@ def test_template_params(self):
275 275
         """
276 276
         response = self.client.get('/template/simple/bar/')
277 277
         self.assertEqual(response.status_code, 200)
278  
-        self.assertEqual(response.context['params'], {'foo': 'bar'})
  278
+        self.assertEqual(response.context['foo'], 'bar')
279 279
         self.assertTrue(isinstance(response.context['view'], View))
280 280
 
281 281
     def test_extra_template_params(self):
@@ -284,7 +284,7 @@ def test_extra_template_params(self):
284 284
         """
285 285
         response = self.client.get('/template/custom/bar/')
286 286
         self.assertEqual(response.status_code, 200)
287  
-        self.assertEqual(response.context['params'], {'foo': 'bar'})
  287
+        self.assertEqual(response.context['foo'], 'bar')
288 288
         self.assertEqual(response.context['key'], 'value')
289 289
         self.assertTrue(isinstance(response.context['view'], View))
290 290
 

0 notes on commit f04bb6d

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