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)
Change History (7)
by , 13 years ago
Attachment: | TemplateView.diff added |
---|
comment:1 by , 13 years ago
Cc: | added |
---|
comment:2 by , 13 years ago
Summary: | TemplateResponseView get_context_data returns params dict → TemplateView get_context_data returns params dict |
---|
comment:3 by , 13 years ago
Keywords: | class-based generic view TemplateView added |
---|
comment:4 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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 , 13 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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 , 13 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
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.
typo in description - TemplateView not TemplateResponseView