i have a code , i have login form whenever the user fill login form than form will render to home page. but i want to print username in the home page who is logged in.
views.py :
this is login function , when user fill login form than it authenticate the values and render to the home page.
def userLogin(request,template=None,context=None):
if request.user.is_authenticated():
return HttpResponseRedirect('/home/')
if request.method == 'POST':
form = userLoginform(request.POST)
if form.is_valid():
# authenticated_user = form.save()
# login(request, authenticated_user)
return HttpResponseRedirect("/home/")
else:
template=u"registration/login.html"
context= {"form": form}
return render(request, template,context)
else:
form=userLoginform()
template=u"registration/login.html"
context= {"form": form}
return render(request, template,context)
whenever i use this code , the user is logged in properly but the session value is not working , when i used {{ user.username }} in home page then it will not display session values.
request.user.username
in the template he will need to add'django.core.context_processors.request'
to his settings – user1593705