flask_DAy1

 

 

 

from flask import Flask,render_template,request,redirect,session
# app=Flask(__name__)
app = Flask(__name__.split('.')[0],static_folder='statics',static_url_path='/static')
app.secret_key='asdfasdfadfadsewerwsdfd'
@app.route('/login',methods=['GET','POST'])
def login():
    if request.method=="POST":
        name=request.form.get('name')      #通过表单post传过来
        pwd=request.form.get('pwd')      #通过表单post传过来# request.args   #GEt
        if name=='admin' and pwd == '123':
            session['user']=name
            return redirect('/index')
        return render_template('login.html',error='用户名或者密码错误')

    else:

        return render_template('login.html')

@app.route('/index')
def index():
    user=session.get('user')  #session 保存在签名的cookie中
    if not user:
        return redirect('/login')
    return render_template('index.html')

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

  

posted @ 2020-04-11 11:07  巨兽~墨菲特  阅读(129)  评论(0编辑  收藏  举报