Parameterized reusable blocks with Jinja2 (Flask) templating engine

后端 未结 2 1536
独厮守ぢ
独厮守ぢ 2021-02-15 14:15

In Jinja2 templating engine (using Flask), I want to achieve something like that:

{% reusable_block avatar(user) %}
     

        
2条回答
  •  粉色の甜心
    2021-02-15 14:47

    You can use macros.

    {% macro input(name, value='', type='text', size=20) -%}
        
    {%- endmacro %}
    
    
    

    {{ input('username') }}

    {{ input('password', type='password') }}

    More documentation here.

提交回复
热议问题