def find_referenced_templates(ast):
 for node in ast.find_all((nodes.Extends, nodes.FromImport, nodes.Import, nodes.Include)):
  if (isinstance(node.template, nodes.Const) and isinstance(node.template.value, basestring)):
   (yield node.template.value)
  else:
   (yield None)

def find_referenced_templates ( ast ) : for node in ast . find_all ( ( nodes . Extends , nodes . FromImport , nodes . Import , nodes . Include ) ) : if ( isinstance ( node . template , nodes . Const ) and isinstance ( node . template . value , basestring ) ) : ( yield node . template . value ) else : ( yield None )
finds all the referenced templates from the ast .