博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
登录之后更新导航
阅读量:4358 次
发布时间:2019-06-07

本文共 525 字,大约阅读时间需要 1 分钟。

1.用上下文处理器app_context_processor定义函数

  1. 获取session中保存的值
  2. 返回字典
    上下文处理器@app.context_processordef mycontext():    username = session.get('user')    if username:        return{'username':username}    else:        return{}

     

2.在父模板中更新导航,插入登录状态判断代码。

  1. 注意用{% ... %}表示指令。
  2. {
    { }}表示变量
    {% if username %}    
  3. {
    { username }}
  4. 注销
  5. {% else %} 登陆 注册 {% else if %}

     

3.完成注销功能。

  1. 清除session
  2. 跳转
    @app.route('/logout/')def logout():    session.clear()    return redirect(url_for('base'))

     

转载于:https://www.cnblogs.com/1031353319qq/p/7892300.html

你可能感兴趣的文章
单点登陆(SSO)
查看>>
HR,也确实“尽职尽责”
查看>>
MaxComputer 使用客户端配置
查看>>
20190823 顺其自然
查看>>
阅读《余生有你,人间值得》有感
查看>>
每日英语
查看>>
SpringCloud+feign 基于Springboot2.0 负载均衡
查看>>
【BZOJ5094】硬盘检测 概率
查看>>
大庆金桥帆软报表案例
查看>>
Proxy模式
查看>>
读书多些会怎样
查看>>
HDU 2188------巴什博弈
查看>>
tp5任务队列使用supervisor常驻进程
查看>>
Xmind?
查看>>
spring+quartz 实现定时任务三
查看>>
day2-三级菜单
查看>>
linux下升级4.5.1版本gcc
查看>>
Beanutils
查看>>
FastJson
查看>>
excel4j
查看>>