#login redirect depends upon username
9 messages · Page 1 of 1 (latest)
You override https://ccbv.co.uk/projects/Django/5.0/django.contrib.auth.views/LoginView/#get_success_url this method usually
LoginView in Django 5.0.
Display the login form and handle the login action.
how?? there is no topic about login redirect based on user
if self.request.user.username == "user1":
return reverse("home_for_user1")
I suppose. Didn't try it so not sure if request.user is filled directly here, but even if it's not fix won't be that hard too
ok
Is this an app for 5 users?
Anyway. I think better approach is to leave login views as they is, and create one page with including home1.html, home2.html ... depends on
sth like this
@login_required
def home_view(request):
return render(request, 'home.html', {'username': request.user.username})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
{% if username == 'user1' %}
{% include 'homepage1.html' %}
{% elif username == 'user2' %}
{% include 'homepage2.html' %}
{% elif username == 'user3' %}
{% include 'homepage3.html' %}
{% else %}
<p>Welcome, {{ username }}!</p>
<p>This is a default homepage for users without a specific template.</p>
{% endif %}
</body>
</html>
ok I'll try
Is there a some sort of "role" or "level" implementation with your users? Anything will multiple if - else block based on individual users would create issues in not-so-long term.
Maybe its an app only for family members 🙂