您当前的位置: 首页 >  django

IT之一小佬

暂无认证

  • 1浏览

    0关注

    1192博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Django博客系统(首页用户名展示)

IT之一小佬 发布时间:2021-09-29 14:55:49 ,浏览量:1

1. 用户名写入到cookie
# 响应登录结果
response =  redirect(reverse('home:index'))

# 设置状态保持的周期
if remember != 'on':
    # 没有记住用户:浏览器会话结束就过期
    request.session.set_expiry(0)
    # 设置cookie
    response.set_cookie('is_login', True)
    response.set_cookie('username', user.username, max_age=30 * 24 * 3600)
else:
    # 记住用户:None表示两周后过期
    request.session.set_expiry(None)
    # 设置cookie
    response.set_cookie('is_login', True, max_age=14*24 * 3600)
    response.set_cookie('username', user.username, max_age=30 * 24 * 3600)
#返回响应
return response
2. Vue渲染首页用户名

1.index.html


  • [[username]]
    写文章 个人信息 退出登录
  • 登录
  • 2.index.js

    mounted(){
        //获取用户名信息
        this.username=getCookie('username');
        //获取是否登录信息
        this.is_login=getCookie('is_login');
    },

     效果展示:

    关注
    打赏
    1665675218
    查看更多评论
    立即登录/注册

    微信扫码登录

    0.1573s