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.
To reliably get the session key, you need to make sure the session has been created first. The documentation mentions a .create() session method, which can be used to make sure there's a session key:
def my_view(request):
if not request.session.session_key:
request.session.create()
print(request.session.session_key)