Python/Flask
macro & caller 사용 예문
paddre
2020. 7. 5. 23:42
=====================
call.html
=====================
{% macro render_dialog(title, class='dialog')-%}
<div class = "{{ class }}">
<h2>{{title}}</h2>
<div class = "contents">
{{caller()}}
</div>
</div>
{%- endmacro %}
{% call render_dialog('Call Blocl') %}
call block과 매크로 동시 사용
{% endcall%}
===========
execution.py
===========
from jinja2 import Environment, FileSystemLoader
file_loader = FileSystemLoader('templates')
env = Environment(loader=file_loader)
template = env.get_template("call.html")
template.render()
print(template.render())
==============================
실행결과
==============================