from django.shortcuts import render
from django.contrib.auth.models import User
from django.contrib.sessions.models import Session
def get_user_from_session(session_key):
try:
session = Session.objects.get(session_key = session_key)
uid = session.get_decoded().get('_auth_user_id')
return User.objects.get(pk = uid)
except:
return None
def SessionUser(request):
sessionid = request.COOKIES.get('sessionid')
user = get_user_from_session(sessionid)
context = {'username' : user.username}
response = render(request, 'user.html', context)
return response
from django.contrib.auth.models import User
from django.contrib.sessions.models import Session
def get_user_from_session(session_key):
try:
session = Session.objects.get(session_key = session_key)
uid = session.get_decoded().get('_auth_user_id')
return User.objects.get(pk = uid)
except:
return None
def SessionUser(request):
sessionid = request.COOKIES.get('sessionid')
user = get_user_from_session(sessionid)
context = {'username' : user.username}
response = render(request, 'user.html', context)
return response
Комментариев нет:
Отправить комментарий