Flask-Session

Session

  • 对于敏感、重要的信息,建议要存储在服务器端,不能存储在浏览器中,如用户名、余额、等级、验证码等信息
  • 在服务器端进行状态保持的方案就是Session
  • Session依赖于Cookie

session数据的获取

session:请求上下文对象,用于处理http请求中的一些数据内容

@app.route('/index1')
def index1():
    session['username'] = 'itcast'
    return redirect(url_for('index'))
@app.route('/')
def index():
    return session.get('username')

记得设置secret_key: app.secret_key = 'itheima' secret_key的作用:https://segmentfault.com/q/1010000007295395

猜你喜欢

转载自blog.csdn.net/qq_29286967/article/details/80948336
今日推荐