Parameterized reusable blocks with Jinja2 (Flask) templating engine

后端 未结 2 1542
独厮守ぢ
独厮守ぢ 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:34

    I think you're looking for macros

    0 讨论(0)
  • 2021-02-15 14:47

    You can use macros.

    {% macro input(name, value='', type='text', size=20) -%}
        <input type="{{ type }}" name="{{ name }}" value="{{value|e }}" size="{{ size }}">
    {%- endmacro %}
    
    
    <p>{{ input('username') }}</p>
    <p>{{ input('password', type='password') }}</p>
    

    More documentation here.

    0 讨论(0)
提交回复
热议问题