#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.d5c86606a30a9ab7cda494803cb51ced%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to