Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out the request.session sessionid and use it as a variable?

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 session id as a variable in a similar way. Is this documented anywhere? I can't find it.

like image 482
rmh Avatar asked Feb 08 '09 18:02

rmh


People also ask

How can I get session data in Django?

session_data : Django stores the session data in the encoded format. To get the raw data, use the get_decoded() method of the session object.

Which value is a session ID?

The SessionID property is used to uniquely identify a browser with session data on the server. The SessionID value is randomly generated by ASP.NET and stored in a non-expiring session cookie in the browser. The SessionID value is then sent in a cookie with each request to the ASP.NET application.

What is Session ID example?

The session ID can be defined by a command line option or a resource. The session ID can be a single value; for example “Smith". A set of session Ids can be defined; for example, Smith+n where n is 3 would make 3 session Ids available, “Smith1", “Smith2", and “Smith3". Each 5250 session has a unique session ID.


2 Answers

request.session.session_key 

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.

like image 90
dalore Avatar answered Sep 28 '22 02:09

dalore


Django sessions save their key in a cookie. At least its middleware extracts it like this:

from django.conf import settings session_key = request.COOKIES[settings.SESSION_COOKIE_NAME] 
like image 24
che Avatar answered Sep 28 '22 01:09

che