﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27722	"if a template context is an instance of get_template(), it will raise ""TypeError: context must be a dict rather than RequestContext"""	Sayid Munawar	nobody	"This simple view:
{{{
from django.views.generic import TemplateView
from django.template.loader import get_template

class Ngopi(TemplateView):
    template_name = 'base.html'

    def get_context_data(self, **kwargs):
        context = super(Ngopi, self).get_context_data(**kwargs)
        context.update({
            'menu': get_template('menu.html')
            })
        return context
}}}

with `base.html`:
{{{
<html>
	<body>
		<h1>Ngeteh</h1>
		{% include menu %}
	</body>
</html>
}}}

and `menu.html`:
{{{
<ul>
	<li>Ngeteh</li>
	<li>Ngopi</li>
</ul>
}}}

This situation will raise this exception:
{{{
Traceback (most recent call last):
  File ""/Users/ayik/Repo/Django/django/django/core/handlers/exception.py"", line 38, in inner
    response = get_response(request)
  File ""/Users/ayik/Repo/Django/django/django/core/handlers/base.py"", line 217, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File ""/Users/ayik/Repo/Django/django/django/core/handlers/base.py"", line 215, in _get_response
    response = response.render()
  File ""/Users/ayik/Repo/Django/django/django/template/response.py"", line 107, in render
    self.content = self.rendered_content
  File ""/Users/ayik/Repo/Django/django/django/template/response.py"", line 84, in rendered_content
    content = template.render(context, self._request)
  File ""/Users/ayik/Repo/Django/django/django/template/backends/django.py"", line 66, in render
    return self.template.render(context)
  File ""/Users/ayik/Repo/Django/django/django/template/base.py"", line 207, in render
    return self._render(context)
  File ""/Users/ayik/Repo/Django/django/django/template/base.py"", line 199, in _render
    return self.nodelist.render(context)
  File ""/Users/ayik/Repo/Django/django/django/template/base.py"", line 990, in render
    bit = node.render_annotated(context)
  File ""/Users/ayik/Repo/Django/django/django/template/base.py"", line 957, in render_annotated
    return self.render(context)
  File ""/Users/ayik/Repo/Django/django/django/template/loader_tags.py"", line 212, in render
    return template.render(context)
  File ""/Users/ayik/Repo/Django/django/django/template/backends/django.py"", line 64, in render
    context = make_context(context, request, autoescape=self.backend.engine.autoescape)
  File ""/Users/ayik/Repo/Django/django/django/template/context.py"", line 285, in make_context
    raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__)
TypeError: context must be a dict rather than RequestContext.
}}}

This is fine with django 1.10, but not master (mine is currently 1.11.dev20170109230310)

a quick workaround is to edit [https://github.com/django/django/blob/ecb59cc6579402b68ddfd4499bf30edacf5963be/django/template/backends/django.py#L63 django/template/backends/django.py Line 63] to be like this:
{{{
    def render(self, context=None, request=None):
        if isinstance(context, dict):  # <-- my temporary workaround
            context = make_context(context, request, autoescape=self.backend.engine.autoescape)
        try:
            return self.template.render(context)
        except TemplateDoesNotExist as exc:
            reraise(exc, self.backend)
}}}"	Bug	closed	Template system	1.11	Release blocker	fixed		FunkyBob Aymeric Augustin	Accepted	1	0	0	0	0	0
