1.代码
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>宏的导入</title>
</head>
<body>
{%import 'form.html' as form %}
<div style="color:#0000F">
<p>用户名:{{form.input('username')}}</p>
<p>密 码:{{form.input('password',type='password')}}</p>
<p>登 陆:{{form.input('submit',type='submit',value='登陆')}}</p>
</div>
</body>
</html>
form.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>宏定义的使用</title>
</head>
<body>
{#宏定义#}
{%macro input(name,type='text',value='')-%}
<input type="{{type}}" name="{{name}}" value="{{value}}">
{%- endmacro %}
</body>
</html>
app.py
from flask import Flask,render_template
app=Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run()
2.运行结果