from jinja2 import Environment, FileSystemLoader, FunctionLoader



persons = [
    {"name": "Алексей", "old": 18, "weight": 78.5},
    {"name": "Николай", "old": 28, "weight": 82.5},
    {"name": "Иван", "old": 33, "weight": 94.0}
]

# Загручик файлов
def test_1():
    file_loader = FileSystemLoader('')
    env = Environment(loader=file_loader)

    tm = env.get_template('main.html')
    msg = tm.render(users=persons)
    print(msg)


#
def test_3():
    file_loader = FileSystemLoader('')
    env = Environment(loader=file_loader)

    tm = env.get_template('page.html')
    msg = tm.render(domain='http://proproprogs.ru', title='Про Jinja')

    print(msg)


# Загрузчик на основе функций
def load_tpl(path):
    if path == "index":
        return '''Имя {{u.name}}, возраст {{u.old}}'''
    else:
        return '''Данные: {{u}}'''


def test_2():
    func_loader = FunctionLoader(load_tpl)
    env = Environment(loader=func_loader)

    tm = env.get_template('index') # Template
    msg = tm.render(u=persons[0])
    print(msg)



def main():
    test_3()


if __name__ == '__main__':
    main()