@@ -22,6 +22,8 @@ def __init__(self, template, block_name):
2222 self .source = template .source
2323
2424 def render (self , context ):
25+ "Display stage -- can be called many times"
26+
2527 # Make a copy of the context and reset the rendering state.
2628 # Trying to re-use a RenderContext in multiple renders can
2729 # lead to TemplateNotFound errors, as Django will skip past
@@ -30,16 +32,20 @@ def render(self, context):
3032 context_instance = copy (context )
3133 context_instance .render_context = RenderContext ()
3234
33- # Bind the template to the context.
34- with context_instance .render_context .push_state (self .template ):
35- with context_instance .bind_template (self .template ):
36- context .template_name = self .name
35+ with context_instance .render_context .push_state (self ):
36+ if context_instance .template is None :
37+ with context_instance .bind_template (self ):
38+ context .template_name = self .name
39+ return self ._render (context_instance )
40+ else :
41+ return self ._render (context_instance )
3742
38- # Before trying to render the template, we need to traverse the tree of
39- # parent templates and find all blocks in them.
40- self ._build_block_context (self .template , context_instance )
43+ def _render (self , context ):
44+ # Before trying to render the template, we need to traverse the tree of
45+ # parent templates and find all blocks in them.
46+ self ._build_block_context (self .template , context )
4147
42- return self ._render_template_block (context_instance )
48+ return self ._render_template_block (context )
4349
4450 def _build_block_context (self , template : Template , context : Context ) -> None :
4551 """
0 commit comments