首页 > 其他 > 详细

模板宏的使用

时间:2019-11-25 00:56:46      阅读:76      评论:0      收藏:0      [点我收藏+]

一.模板宏的使用

  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 %}

 

模板宏的使用

原文:https://www.cnblogs.com/tjp40922/p/11925096.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!