Flask-不带参数的宏的定义与使用
2020-09-26 本文已影响0人
测试探索
定义
image.pngfrom flask import Flask,render_template,request
app = Flask(__name__)
@app.route("/")
def index():
return render_template("macro_test.html")
if __name__ == '__main__':
app.run(debug=True)
macro_test.html
<!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() }}
</body>
</html>
实现结果