Search code examples
pythondjangodjango-viewsdjango-templates

From Django 1.11 onwards, context passed in render method should be a dictionary rather than a Context object. Then how context.render_context works?


render() in django.shortcuts calls render_to_string method of loader module, which calls render method of Template class by creating a Template object. Till now, context is a dictionary. Inside render method in Template class,

context.render_context.push_state(self):

How does this works? Because render_context is an attribute of Context class which gets assigned a RenderContext object. So, how context being not an instance of Context class can access its attribute?


Solution

  • context is being setup when calling Template render method

    context = make_context(
        context, request, autoescape=self.backend.engine.autoescape
    )
    

    make_context