1
I am trying to make a redirect of users based on functions, example: an admin after the login is sent to the admin, the attendant or common employee, be sent to a home, but the code placed does not redirect, just back to home, for all functions, how to solve?
VIEWS
@login_required
def login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user.is_active:
# Redirecting to the required login according to user status.
if user.is_superuser or user.is_staff:
login(request, user)
return HttpResponseRedirect('admin') # or your url name
else:
login(request, user)
return redirect('')
SETTING.PY
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = 'home'
Oh my dear, thank you very much, that’s right, thank you.
– Acelino Fernandes