[Django] #21154: `TemplateResponse` does not convert `Context` to `RequestContext`.

33 views
Skip to first unread message

Django

unread,
Sep 24, 2013, 10:51:55 AM9/24/13
to django-...@googlegroups.com
#21154: `TemplateResponse` does not convert `Context` to `RequestContext`.
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
mrmachine | Status: new
Type: Bug | Version: master
Component: | Keywords: TemplateResponse Context
Template system | RequestContext
Severity: Normal | Has patch: 0
Triage Stage: | UI/UX: 0
Unreviewed |
Easy pickings: 0 |
-------------------------+-------------------------------------------------
The docs say that `TemplateResponse` is a subclass of
`SimpleTemplateResponse` that uses `RequestContext` instead of `Context`.
It also says that context data can be provided as a dict or as a `Context`
object. However, if a `Context` object is given as context data, it is
left as-is and is not converted to a `RequestContext` object in
`TemplateResponse.resolve_context()`.

Either the docs should be changed to reflect that users must pass a dict
or `RequestContext` (and validate this in code), or the code should be
updated to convert `Context` to `RequestContext` objects. I would suggest
the latter, even though it may be an edge case.

If a user wants to use `TemplateResponse` and they are passed a `Context`
object from somewhere (maybe 3rd party code), there appears to be no user-
friendly way to convert it to `RequestContext` themselves before passing
to `TemplateResponse`. You can't do `RequestContext(request,
context_object)`. It seems you would need to iterate through
`context_object.dicts` and assign each key/value to a new empty
`RequestContext` object in order, or perhaps just `context.dicts` across.

Perhaps updating `RequestContext` to allow `Context` objects as data, and
checking `isinstance(context, RequestContext)` in
`TemplateResponse.resolve_context()` would be a good idea?

--
Ticket URL: <https://code.djangoproject.com/ticket/21154>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 30, 2013, 6:31:20 AM9/30/13
to django-...@googlegroups.com
#21154: `TemplateResponse` does not convert `Context` to `RequestContext`.
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: TemplateResponse | Triage Stage:
Context RequestContext | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by FunkyBob):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Personally, I think it would be better to document this.

If you pass a dict, it will be "upgraded" to a RequestContext.

If you took the trouble to build a Context, it's assumed you did so for a
reason.

--
Ticket URL: <https://code.djangoproject.com/ticket/21154#comment:1>

Django

unread,
Sep 30, 2013, 6:48:50 AM9/30/13
to django-...@googlegroups.com
#21154: `TemplateResponse` does not convert `Context` to `RequestContext`.
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: TemplateResponse | Triage Stage:
Context RequestContext | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by FunkyBob):

I've written some additional docs in the pr:

https://github.com/django/django/pull/1694

--
Ticket URL: <https://code.djangoproject.com/ticket/21154#comment:2>

Django

unread,
Sep 30, 2013, 10:21:10 AM9/30/13
to django-...@googlegroups.com
#21154: `TemplateResponse` does not convert `Context` to `RequestContext`.
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: fixed

Keywords: TemplateResponse | Triage Stage:
Context RequestContext | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"c39c9f2ad8b2670d53ef845face67c29f3f4be3b"]:
{{{
#!CommitTicketReference repository=""
revision="c39c9f2ad8b2670d53ef845face67c29f3f4be3b"
Fixed #21154 -- Updated TemplateResponse docs to better explain context.

Thanks mrmachine for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21154#comment:3>

Django

unread,
Sep 30, 2013, 10:21:49 AM9/30/13
to django-...@googlegroups.com
#21154: `TemplateResponse` does not convert `Context` to `RequestContext`.
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: fixed
Keywords: TemplateResponse | Triage Stage:
Context RequestContext | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"98773c4bb53ff464c3782694f244e80158f975ee"]:
{{{
#!CommitTicketReference repository=""
revision="98773c4bb53ff464c3782694f244e80158f975ee"
[1.6.x] Fixed #21154 -- Updated TemplateResponse docs to better explain
context.

Thanks mrmachine for the report.

Backport of c39c9f2ad8 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21154#comment:4>

Django

unread,
Sep 30, 2013, 10:21:49 AM9/30/13
to django-...@googlegroups.com
#21154: `TemplateResponse` does not convert `Context` to `RequestContext`.
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: fixed
Keywords: TemplateResponse | Triage Stage:
Context RequestContext | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"20f394f4d5a5e0b4647aac2dd7b5ab8dc89d36fa"]:
{{{
#!CommitTicketReference repository=""
revision="20f394f4d5a5e0b4647aac2dd7b5ab8dc89d36fa"
[1.5.x] Fixed #21154 -- Updated TemplateResponse docs to better explain
context.

Thanks mrmachine for the report.

Backport of c39c9f2ad8 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21154#comment:5>

Reply all
Reply to author
Forward
0 new messages