#27258: Context processors are not called when using RequestContext and Django
templates
---------------------------------+--------------------
     Reporter:  Andi Albrecht    |      Owner:  nobody
         Type:  Bug              |     Status:  new
    Component:  Template system  |    Version:  1.10
     Severity:  Normal           |   Keywords:
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+--------------------
 When using RequestContext with a Django template, the context_processors
 are not called to populate the context.

 Here's an simple examle (see also attached test_request_context.py):

 {{{
 #!python
 >>> from django.template.backends.django import DjangoTemplates
 >>> from django.test import RequestFactory
 >>> from django.template import Template, RequestContext
 >>>
 >>> # a simlpe context_processor:
 >>> def test_processor_name(request):
 ...     return {'name': 'Hello World'}
 >>>
 >>> # Create a RequestContext
 >>> request = RequestFactory().get('/')
 >>> context = RequestContext(request, {}, [test_processor_name])
 >>>
 >>> # Base template (everything's fine)
 >>> template = Template('{{ name }}')
 >>> template.render(context)
 <<< u'Hello World'
 >>>
 >>> # Django template :(
 >>> engine = DjangoTemplates({
 ...             'DIRS': [],
 ...             'APP_DIRS': False,
 ...             'NAME': 'django',
 ...             'OPTIONS': {
 ...                 'context_processors': [test_processor_name],
 ...             },
 ...         })
 >>> template = engine.from_string('{{ name }}')
 >>> template.render(context)
 <<< u''
 }}}

 The reason seems to be, that the `render()` method of a Django template
 (as opposed to the base template) calls `make_context` which wraps
 `RequestContext` in another `Context` instance. But when rendering the
 template the `bind_template` context manager only of the outermost
 `Context` instance is called, hence the context of a `RequestContext`
 instance is never populated by context_processors.

--
Ticket URL: <https://code.djangoproject.com/ticket/27258>
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/055.46d63363cfa4e5d0d5a1f14ed2d4d90e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to