简体   繁体   中英

LOGIN_REDIRECT_URL to a specific View

Is there a way to specify a view in the LOGIN_REDIRECT_URL setting in settings.py? I am using django-allauth for registration and logging in.

What i am trying to do is as follows:

When the user is logged in, determine if the user is_user_A or is_user_B (is_user_A being default).

If is_user_A -> redirect to is_user_A-dashboard.html

If is_user_B -> redirect to is_user_B-dashboard.html

My code is as follows:

views.py

def logged_in(request):
   if request.user.is_user_A:
      return render(request, "is_user_A-dashboard.html")
   if request.user.is_user_B:
      return render(request, "is_user_B-dashboard.html")

settings.py

LOGIN_REDIRECT_URL = '/'

you can add a url in your urls.py

url(r'^home$',logged_in , name ="logged_in"),

and put this url in LOGIN_REDIRECT_URL

LOGIN_REDIRECT_URL = '/home'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM