flask-----if语句

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/GoodLuckAC/article/details/79086005

                                           if语句

{% if user.is_logged_in() %}
    <a href='/logout'>Logout</a>
{% else %}
    <a href='/login'>Login</a>
{% endif %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    {% if user %}
       <a href="#"> {{ user.username}}</a>
       <a href="#">注销</a>
    {% else %}
       <a href="#">登录</a>
       <a href="#">注册</a>
    {% endif %}
</body>
</html>
#encoding:utf-8
from flask import Flask,render_template

app = Flask(__name__)


@app.route('/<is_login>/')#127.0.0.1:5000/参数
def index(is_login):
    if is_login=='1':
        user={
            'username':u'二狗',
            'age':18
       }
        return render_template('index.html',user=user)
    else:
         return render_template('index.html')


if __name__ == '__main__':
    app.run()


 
 




猜你喜欢

转载自blog.csdn.net/GoodLuckAC/article/details/79086005