2

I have a little problem with the context.

I have an inclusion tag with the param :

takes_context=True 

In this inclusion's tag's template, I call for another inclusion_tag which has also the param

takes_context = True

But in this last inclusion_tag context is None.

I don't know why ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
rodriguez
  • 21
  • 1

1 Answers1

2

Don't forget that the context for the second inclusion tag is whatever is returned from the first one. If you need the entire context from the original template, it's best to copy it over:

@register.inclusion_tag('template.html', takes_context=True)
def first_inclusion_tag(context, value):
    params = {'value': value}
    params.update(context)
    return params
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • This may be old, but since it seems that today `takes_context=True` causes to be like a list of dictionnaries, I suggest to rather update with `context.flatten()` for latest versions (`params.update(context.flatten())`). – vmonteco Apr 12 '18 at 14:24