模板变量设置 set 和 with

from flask import Flask,render_template


app = Flask(__name__)


@app.route('/')
def hello_world():
    return render_template('set_with_statement.html')


if __name__ == '__main__':
    app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>知了学堂</title>
</head>
<body>
    <!--只有set设置了变量,在哪里都可以用-->
    {% set username = "xiaowu" %}
    <p>{{ username }}</p>
    <!--如果想设置的变量,只能在某一区域能用就是用with来设置-->
    {% with classroom = "python一班" %}
        <p>班级:{{ classroom }}</p>
    {% endwith %}
</body>
</html>

 

posted @ 2018-09-20 11:38  python成长中  阅读(563)  评论(0编辑  收藏  举报