在Django中,如何找到request.session sessionid并将其用作变量? [英] In Django, how can I find out the request.session sessionid and use it as a variable?

查看:1919
本文介绍了在Django中,如何找到request.session sessionid并将其用作变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以使用 request.session ['variable_name'] 获取会话变量,但似乎没有办法抓取sessionid作为变量以类似的方式。这是否记录在任何地方?我找不到它感谢您的帮助!

I'm aware that you can get session variables using request.session['variable_name'], but there doesn't seem to be a way to grab the sessionid as a variable in a similar way. Is this documented anywhere? I can't find it. Thanks for your help!

推荐答案

更简单:

request.session.session_key

注意,只有存在一个会话,没有密钥,没有会话。您可以使用它来测试会话是否存在。如果要创建会话,请调用create。

Note the key will only exist if there is a session, no key, no session. You can use this to test if a session exists. If you want to create a session, call create.

这篇关于在Django中,如何找到request.session sessionid并将其用作变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆