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

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.


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]

in Django >= 1.4 use:

request.session._session_key