SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы

Список вопросов Печать

Вывод древовидной структуры в шаблоне jinja2


Метки: python jinja 

Пример:

comment9
    comment11
comment12
    comment13
    comment14
        comment15
            comment16

Ответы

RemiZOffAlex  Создано: 2017-07-20 18:38:53.493342  Обновлено: 2017-07-20 18:38:53.493342

Пример из документации http://jinja.pocoo.org/docs/dev/templates/

<ul class="sitemap">
{%- for item in sitemap recursive %}
    <li><a href="{{ item.href|e }}">{{ item.title }}</a>
    {%- if item.children -%}
        <ul class="submenu">{{ loop(item.children) }}</ul>
    {%- endif %}</li>
{%- endfor %}
</ul>

Возможно будут интересны и другие вопросы