• [django]session设置与获取原理


    admin登录

    情况1: 登录后会产生一个sessionid

    情况2: 自定义设置了key后,会多一个sessionid, 登录后会替换为登录后的sessionid的key值

            if username == "maotai" and password == "123456":
                request.session['name'] = "maotai-session" #定义一个session key
                request.session['name2'] = "maotai2-session"#定义一个session key
    

    自定义sessionid

    def login(request):
        if request.method == "POST":
            username = request.POST.get("username")
            password = request.POST.get("password")
            if username == "maotai" and password == "123456":
                request.session['name'] = "maotai-session" #定义一个session key
                request.session['name2'] = "maotai2-session"#定义一个session key
    
                name = request.session.get("name", "") # 获取一个session key
                name2 = request.session.get("name2", "")
                # return redirect("/")
                return render(request, "index.html", {"name": name, "name2": name2}) #将session key返回到前端
            else:
                return render(request, "login.html")
        elif request.method == "GET":
            return render(request, "login.html")
    

    获取sessionid

    request.session.get("name", "") # 获取一个session key   获取到的应该是下面的_session里的结果
    

  • 相关阅读:
    根据数据类型选择特征 select_dtypes(include=[]/exclude=[])
    quantile()
    concat()、merge()的区别
    json.dumps()和json.loads()
    Linux-top命令详解
    性能测试总结(一)---基础理论篇
    jmeter-常见问题及解决方法
    Jmeter之Bean shell使用(五)
    Jmeter-内存溢出原因及解决方法
    JMeter- JDBC Request
  • 原文地址:https://www.cnblogs.com/iiiiiher/p/9523888.html
Copyright © 2020-2023  润新知