def resolve_blocks(template, context):
    '''
    Return a BlockContext instance of all the {% block %} tags in the template.

    If template is a string, it will be resolved through get_template
    '''
    try:
        blocks = context.render_context[BLOCK_CONTEXT_KEY]
    except KeyError:
        blocks = context.render_context[BLOCK_CONTEXT_KEY] = BlockContext()

    # If it's just the name, resolve into template
    if isinstance(template, six.string_types):
        template = get_template(template)

    # For Django 1.8 compatibility
    template = getattr(template, 'template', template)

    # Add this templates blocks as the first
    local_blocks = {
        block.name: block
        for block in template.nodelist.get_nodes_by_type(BlockNode)
    }
    blocks.add_blocks(local_blocks)

    # Do we extend a parent template?
    extends = template.nodelist.get_nodes_by_type(ExtendsNode)
    if extends:
        # Can only have one extends in a template
        extends_node = extends[0]

        # Get the parent, and recurse
        parent_template = extends_node.get_parent(context)
        resolve_blocks(parent_template, context)

    return blocks
def resolve_blocks(template, context):
    '''
    Return a BlockContext instance of all the {% block %} tags in the template.

    If template is a string, it will be resolved through get_template
    '''
    try:
        blocks = context.render_context[BLOCK_CONTEXT_KEY]
    except KeyError:
        blocks = context.render_context[BLOCK_CONTEXT_KEY] = BlockContext()

    # If it's just the name, resolve into template
    if isinstance(template, six.string_types):
        template = get_template(template)

    # For Django 1.8 compatibility
    template = getattr(template, 'template', template)

    # Add this templates blocks as the first
    local_blocks = {
        block.name: block
        for block in template.nodelist.get_nodes_by_type(BlockNode)
    }
    blocks.add_blocks(local_blocks)

    # Do we extend a parent template?
    extends = template.nodelist.get_nodes_by_type(ExtendsNode)
    if extends:
        # Can only have one extends in a template
        extends_node = extends[0]

        # Get the parent, and recurse
        parent_template = extends_node.get_parent(context)
        resolve_blocks(parent_template, context)

    return blocks
def resolve_blocks ( template , context ) : try : blocks = context . render_context [ BLOCK_CONTEXT_KEY ] except KeyError : blocks = context . render_context [ BLOCK_CONTEXT_KEY ] = BlockContext ( ) # If it's just the name, resolve into template if isinstance ( template , six . string_types ) : template = get_template ( template ) # For Django 1.8 compatibility template = getattr ( template , 'template' , template ) # Add this templates blocks as the first local_blocks = { block . name : block for block in template . nodelist . get_nodes_by_type ( BlockNode ) } blocks . add_blocks ( local_blocks ) # Do we extend a parent template? extends = template . nodelist . get_nodes_by_type ( ExtendsNode ) if extends : # Can only have one extends in a template extends_node = extends [ 0 ] # Get the parent, and recurse parent_template = extends_node . get_parent ( context ) resolve_blocks ( parent_template , context ) return blocks
Return a BlockContext instance of all the {% block %} tags in the template.

    If template is a string, it will be resolved through get_template
Return a BlockContext instance of all the { % block % } tags in the template .