Reputation: 133
How can I show any user his/her username when logged in at "next.html" page ???
def signin(request):
if request.method != 'POST':
return render(request, 'login.html', {'error': 'Email or Password is incorrect'})
user_profile = User_account.objects.filter(e_mail = request.POST['user_email'], passwd = request.POST['password'])
if user_profile:
return render(request, 'next.html', {'name' :User_account.objects.**WHAT SHOULD I WRITE HERE???** } )
else:
return render(request, 'login.html', {'error': 'Email or Password is incorrect'})
Upvotes: 5
Views: 25964
Reputation: 99620
There are 2 ways you can do it:
a) Directly in the template:
{{request.user.username}}
Or: b)
return render(request, 'next.html', {'name' : request.user.username })
Note that you have not "logged" the user in yet
In your case, you can do:
return render(request, 'next.html', {'name' : user_account.first_name })
You need to call the login
method to actually log the user in, or manually handle the login. This post can give you the way to do it.
Also you would need a request_context processor
Upvotes: 21