macro_demo.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author tom


from flask import Flask,render_template


app = Flask(__name__)

@app.route("/")
def func():
    return render_template("macro.html")


if __name__ == '__main__':
    app.run(debug=True)

  macro.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>模板宏的使用</title>
</head>
<body>
    //不带参数的宏
    {% macro input() %}
        <input type="text" name="" id="" size="30">
    {% endmacro %}

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

    //带参数的宏
    {% macro input2(type,value,size) %}
        <input type="{{ type }}"  value="{{ value }}" size="{{ size }}">
    {% endmacro %}

    <h1>带参数宏</h1>
    {{ input2("text","",50) }}
</body>
</html>

  宏定义在外部

    {% macro input5() %}
        <input type="text"   size="20">
    {% endmacro %}

 

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2022-01-06
  • 2021-06-13
  • 2021-12-25
  • 2022-02-07
  • 2021-08-02
  • 2021-12-07
猜你喜欢
  • 2022-01-23
  • 2021-12-04
  • 2021-07-29
  • 2022-01-08
  • 2022-02-24
  • 2023-02-10
相关资源
相似解决方案