python有宏这种概念吗_25 宏的概念和基本使用

# 25 宏的概念和基本使用

模块中的宏跟python中的函数类似,可以传递参数,但是不能有返回值,可以将一些经常用到的代码片段放到宏中,然后把一些不固定的值抽取出来当成一个变量。

```text

{% marco 函数%}

函数

{% endmarco %}

```

```text

app.py

from flask import Flask, render_template

app = Flask(__name__)

app.config['TEMPLATES_AUTO_RELOAD'] = True

@app.route('/')

def hello_world():

return render_template("index/index.html",username="angle")

if __name__ == '__main__':

app.run(debug=True)

```

```text

index.html

{% import "macros/macros.html" as macros %}

登录

用户名:{{ macros.input("username") }}
密码:{{ macros.input(name="password",type="password") }}
{{ macros.input(value="提交",type="submit") }}

```

```text

macors.html

{% macro input(name="",value="",type="text") %}

{% endmacro %}

```

![](https://box.kancloud.cn/d9341a569825f77a2cc2a98fd98343c0_444x359.png)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值