#25839: RequestContext does not apply context processors [regression]
-------------------------------------+-------------------------------------
     Reporter:  direx                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Template system      |                  Version:  1.8
     Severity:  Release blocker      |               Resolution:
     Keywords:  RequestContext,      |             Triage Stage:  Accepted
  regression                         |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by carljm):

 As part of the multiple-template-engines feature, Django 1.8 refactored
 the Django template language to remove the direct coupling to global
 settings, instead making it possible to instantiate multiple
 independently-configured `Engine` instances (and configure multiple such
 instances via the new `TEMPLATES` setting). Because of this, it's no
 longer possible for `RequestContext` to automatically fetch the list of
 configured context processors from settings (the `TEMPLATES` setting can
 define multiple instances of the DTL with different lists of context
 processors, so how could `RequestContext` possibly know which list of
 context processors to use?). This was handled by adding a new context-
 manager method `RequestContext.bind_template` which temporarily binds a
 `RequestContext` to a template instance, in the process applying all the
 context processors from that template's engine configuration.

 This solution is fully backwards-compatible for the only documented usage
 of a `RequestContext`, which is to pass it into a template render and
 access its values in the template. It's true that it's not backwards-
 compatible for the usage you demonstrate, directly accessing values from
 the context as a dictionary without rendering a template, but this is not
 a documented or supported mode of use for `RequestContext`. If you need
 this usage, you must now first bind the context to a specific template:

 {{{
 from django.template import engines

 engine = engines['default']
 tpl = engine.get_template('some/template.html')
 ctx = RequestContext(request)
 with ctx.bind_template(tpl):
     print(ctx['user'])
 }}}

 It may be possible to restore the old behavior for this usage using
 `Engine.get_default()` (it would only work if there's only a single
 instance of the DTL configured in settings); personally I don't think
 that's worth doing, or that this use of `RequestContext` should be
 supported.

 Alternatively, we could add a warning to the 1.8 release notes about this,
 but this usage is so unusual that I'm not even sure that's worth doing.

--
Ticket URL: <https://code.djangoproject.com/ticket/25839#comment:2>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.3f1180d72ef74307cb49715c6b9a586c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to