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

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

Jinja2 vs Mako


Метки: jinja mako python шаблонизатор 

Ответы

RemiZOffAlex  Создано: 2021-06-11 17:03:53.247734  Обновлено: 2025-06-10 01:44:00.931011
Jinja2 Mako
{% block title %}{% endblock %}
<%block name="title"/>
{% extends "base.html" %}
<%inherit file="base.html"/>
{% include "base.html" %}
<%include file="base.html"/>
 
<%include file="header.txt" args="title=title,link=pr_comment_url"/>
{% if condition %}
{% elif condition2 %}
{% else %}
{% endif %}
%if condition:
%elif condition2:
%else:
%endif
{% for i in items %}
{% endfor %}
%for i in items:
%endfor
{% for i in items %}
{{ loop.index }}
{% endfor %}
%for idx,i in enumerate(items):
%endfor
{% macro breadcrumbs() %}
{% endmacro %}

{{ breadcrumbs() }}
<%def name="breadcrumbs()">
</%def>

${self.breadcrumbs()}
{% import 'file.html' as mymodule with context %}
<%namespace name="mymodule" file="file.html"/>
 
# root.html
${next.body()}

# base.html
<%inherit file="root.html"/>
{% if item|attr('field') %}
%if hasattr(item, 'field'):
Фильтры
{{ "this is some text"|urlencode }}

Фильтр обрабатывает пробел как символ %20

${"this is some text" | u}

Фильтр обрабатывает пробел как +

x|length
len(x)
elements|map(attribute='attrname')|join(', ')
', '.join((x.attrname for x in elements))

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