I am try to write a function that gets the username
of the person logged and right after that changes de session_key
into a new one.
What I have written so far is this:
def get_username(request):
try:
for coisa in request:
session_key = coisa # This seems to be wrong, but it works
session = Session.objects.get(session_key=session_key)
user_id = session.get_decoded().get('_auth_user_id')
user = User.objects.get(id=user_id) # Works very well until here, trust me
session.cycle_key() #this is where I'm getting the error
return HttpResponse(user.username)
except Exception, e:
print 'Erro: ' + str(e)
return HttpResponseServerError(str(e))
That request variable I'm passing is not the usual django request, it's a request built by a javascript script and has only the session_key on its data.
The error I'm getting is this: 'Session' object has no attribute 'cycle_key'
The session_key I'm using on this function came from a function that runs when the page is going to load, so that request
is a "normal" request variable from django:
session_key = request.session.session_key