I have a new django project I am working on. I am integrating Djangos user login and logout service that comes with the framework. I have a view and within the view, I want to check and see if there is a user
object in the request.user
. if there is not, I want to redirect to login page. If there is a user
in the request.user
, I want to display the users home page. how can I do this. Here is my code:
def home(request):
if not request.user:
return redirect('login')
else:
User = request.user
profile = Profile.objects.get(user = User)
parameters = {
'user':User,
'profile':profile,
}
return render(request, 'user/home.html', parameters)
It works if there is a user logged in but doesnt work if there is no user logged in...