How to get username form django session
i am trying to get user name from session by using request.user but i am getting AnonymousUser, how do i get user name
def login_two(request):
if request.method == 'POST':
uname = request.POST.get('name2')
pwd = request.POST.get('password2')
check_user = User.objects.filter(username=uname, password=pwd)
if check_user:
request.session['user'] = uname
return redirect('index')
return render(request, 'login2.html')
models.py
class User(models.Model):
username = models.CharField(max_length=30)
password = models.CharField(max_length=50)