#24694: Add support for OPTIONS['context_processors'] to Jinja2 template backend
---------------------------------+------------------------------------
     Reporter:  carljm           |                    Owner:  nobody
         Type:  New feature      |                   Status:  new
    Component:  Template system  |                  Version:  master
     Severity:  Normal           |               Resolution:
     Keywords:                   |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+------------------------------------

Comment (by carljm):

 Replying to [comment:4 adamkerz]:
 > I've just run into the same problem trying to use jinja2 and had a bit
 of a look at middleware and the process_template_response method. From my
 minor experimentation, it looks to me like that's at least roughly
 equivalent to a context_processor - is there a reason that we can't get
 rid of context_processors in favour of middleware? Seems like it will
 support any template engine out of the box without having to modify the
 template backend.
 >
 > What are the differences between the two?

 That's a very good point; I hadn't thought of that. I've used
 `TemplateResponse` quite a bit with view _decorators_, but never really
 with the middleware, so I hadn't thought of it as a "global" option.

 That said, they aren't quite equivalent: `process_template_response` has
 no effect unless you return a `TemplateResponse`. If you render a template
 in any other way (say, render a template for creating an email or
 something), or if you have a view from a third-party app that doesn't
 return a `TemplateResponse`, your `process_template_response` will have no
 effect. So I don't think we can consider `process_template_response` a
 full replacement for context processors, but you're right that they can be
 used similarly.

 > Also, doesn't django.utils.functional.lazy get around issues of loading
 it whether it's used or not?

 Heh. Yeah, if you're willing to wrap everything in it :-) `lazy` is a
 pretty nasty hack, and its abstraction leaks sometimes. If you're using
 Jinja, I think a better solution than `lazy` is usually to just include a
 function in the template context, and call it in the template.

--
Ticket URL: <https://code.djangoproject.com/ticket/24694#comment:5>
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/064.6c5e55aa712e103ec21553d2aa4c87cf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to