Opened 13 years ago

Closed 13 years ago

#16642 closed Bug (invalid)

TemplateView get_context_data returns params dict

Reported by: martinogden Owned by: martinogden
Component: Generic views Version: 1.3
Severity: Normal Keywords: class-based generic view, TemplateView
Cc: martinogden Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

the TemplateResponseView class based view should return kwargs as a dict when calling get_context_data (same as all the other class based views), however it returns the kwargs as {'params': kwargs} therefore they are extra context is namespaced (e.g. {{ params.extra_data }} rather than {{ extra_data }} as documented.

Attachments (1)

TemplateView.diff (492 bytes ) - added by martinogden 13 years ago.

Download all attachments as: .zip

Change History (7)

by martinogden, 13 years ago

Attachment: TemplateView.diff added

comment:1 by martinogden, 13 years ago

Cc: martinogden added

comment:2 by martinogden, 13 years ago

Summary: TemplateResponseView get_context_data returns params dictTemplateView get_context_data returns params dict

comment:3 by martinogden, 13 years ago

Keywords: class-based generic view TemplateView added

typo in description - TemplateView not TemplateResponseView

comment:4 by Aymeric Augustin, 13 years ago

Resolution: invalid
Status: newclosed

TemplateView behaves according to the documentation. params is intended to contain the parameters captured in the URL.

See https://docs.djangoproject.com/en/dev/ref/class-based-views/#django.views.generic.base.TemplateView

comment:5 by simon@…, 13 years ago

Resolution: invalid
Status: closedreopened

This behaviour seems rather undesirable. The TemplateView is meant to be the quickest and easiest way of rendering a template. Why does it encapsulate the kwargs inside a redundant single-element dictionary? Having to change the templates to include params feels totally wrong.

Is there an alternative class-based view that doesn't require the use of 'params'?

comment:6 by Russell Keith-Magee, 13 years ago

Resolution: invalid
Status: reopenedclosed

The params dictionary isn't redundant at all -- it's a namespace. The parameters passed in to the view aren't the only context variables that the template can render. Consider the case where the arguments passed in part of the URL pattern overlap with context variables created by the view.

Note: See TracTickets for help on using tickets.
Back to Top