模板if 的使用


from flask import Flask,render_template


app = Flask(__name__)

app.debug = True


@app.route('/')
def hello_world():
    context = {
        'username':'laonanhai'
    }
    return render_template('if_used.html',**context)


if __name__ == '__main__':
    app.run()
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>if模板使用</title>
</head>
<body>
    <h1>if邏輯的使用,在模板中怎么使用</h1>
    <!--jinja2模板的if語句幾乎和python中的一樣-->
    {% if username=='laonanhai' %}
        <p>老男孩是狗比</p>
    {% else %}
        <p>老男孩豬狗不如</p>
    {% endif %}
    {% if username == 'goubi' %}
        <p>老男孩是狗比</p>
    {% elif username == 'laonanhai' %}
        <p>老男孩豬狗不如</p>
    {% endif %}
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM