Context passed to render disappears when inheritance is used #134

khiltd opened this Issue Jun 3, 2012 · 1 comment


None yet

1 participant


I'm 99% positive that I'm doing something wrong here, but the documentation really doesn't seem to explain what I'm seeing, and tracing through the rendering pipeline is pretty arduous, so I'm hoping for a simple explanation.

Using FileSystemLoader, I create a context and pass it to each Templates render method like so:

env = Environment(  loader=FileSystemLoader(["./layouts"]),
                        trim_blocks=True ,
                        autoescape=False )

context     =   { "negasonic": "deny" }

for path in env.loader.list_templates():
    template    = env.get_template(path, context)
    output        = template.render(context).encode("utf-8") 
    print output

If a file in ./layouts contains this:

{{ negasonic }}

Then the output is predictably


If a file in ./layouts uses inheritance to extend another file in ./layouts:

{% extends "base.j2" %}
{% block content %}
    {{ super() }}
{% endblock content %}
{{ negasonic }}

The ouput then contains everything from base.j2 and the output of its content block, but the variable negasonic disappears and is not expanded.

I have tried adding the contents of my context dict to the Environment's globals as well as to the Template's globals, and this makes no difference. So my questions are:

  1. Why is my context emptied when I use the extends keyword?

  2. How can a template file dump out a textual representation of everything that it is being passed so I can debug via introspection in cases where the documentation simply isn't very clear?



Moving the {{ negasonic }} into the content block results in the expected output, so surely this must be a case of me completely misunderstanding how the rendering contexts are scoped in cases where inheritance is involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment