i created a function in my views.py file which lets you see different dashboards according to the role of the email which is logging in now when im trying to fetch the id of user im getting the id of the user which was loggod on the server before what chnages should i be doing for this.I tried clearing the session during logout but it's still not working and the code is fetching me the id of previous logged in admin.
def determine_role(request):
user = request.user # Get the authenticated user object
role = user.role # Access the role attribute
# Now you can use the role to perform further actions
if role == 'admin':
# If the user is an admin, do something
return render(request, 'loginapp/admin_dashboard.html')
elif role == 'user':
# If the user is a regular user, do something else
return render(request, 'loginapp/user_dashboard.html')
I don't know if you are cleaning your session manually. If so, you should use the
logoutfunction that Django provides you to log a user out. You can find this function indjango.contrib.auth.logout(). According to Django's documentation: