Opened 5 years ago

Closed 5 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


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 5 years ago.

Download all attachments as: .zip

Change History (7)

Changed 5 years ago by martinogden

Attachment: TemplateView.diff added

comment:1 Changed 5 years ago by martinogden

Cc: martinogden added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 5 years ago by martinogden

Summary: TemplateResponseView get_context_data returns params dictTemplateView get_context_data returns params dict

comment:3 Changed 5 years ago by martinogden

Keywords: class-based generic view TemplateView added

typo in description - TemplateView not TemplateResponseView

comment:4 Changed 5 years ago by Aymeric Augustin

Resolution: invalid
Status: newclosed

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


comment:5 Changed 5 years ago by simon@…

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 Changed 5 years ago by Russell Keith-Magee

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