Flask-带参数的宏的定义-宏的封装

2020-09-27  本文已影响0人  测试探索

接上一篇文章,可先将宏封装在一个html中,本次我们定义封装宏的html为macro_input.html,内容如下

{% macro input4(type="text",value="",size=30) %}
    <input type="{{ type }}" value="{{ value }}" size="{{ size }}">
    {% endmacro %}

在macro_test文件中,先导入,再调用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    {% macro input() %}
    <input type="text" value="" size="30">
    {% endmacro %}

    <h1>input 1</h1>
    {{ input() }}

    <h1>input 2</h1>
    {{ input() }}

    <hr/>
    {% macro input2(type,value,size) %}
    <input type="{{ type }}" value="{{ value }}" size="{{ size }}">
    {% endmacro %}

    <h1>input 3</h1>
    {{ input2("password","",50) }}

{#导入#}
    <hr/>
    {% import "macro_input.html" as m_input %}
    <h1>input4</h1>
    {{ m_input.input4()  }}
</body>
</html>
运行结果
上一篇 下一篇

猜你喜欢

热点阅读