模板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