简体   繁体   English

如何根据Django中的管理员或工作人员重定向登录URL

[英]How to redirect login urls depending upon user is admin or staff in django

I am new in django . 我是Django的新手。 I need to redirect login page depending upon the user is admin or staff. 我需要根据用户是管理员还是工作人员来重定向登录页面。 if the user is admin i need redirect in to /dashboard . 如果用户是管理员,则需要重定向到/dashboard If the staff is longed in then redirect in to /Profile How can i do this. 如果工作人员很渴望,请重定向到/Profile 。我该怎么做。

In my view 在我看来

url(r'^$', 'django.contrib.auth.views.login', {'redirect_field_name': 'next'}, name='login'),

in settings.py : settings.py

LOGIN_REDIRECT_URL = '/dashboard/'

You can use django's request functionality 您可以使用Django的请求功能

def my_view(request):
    if request.user.is_superuser:
        #your logic here
        return redirect("/admin/")# or your url name
    if request.user.is_staff:
        #your logic here
        return redirect("/dashboard/")# or your url name

You can do according to your requirement. 您可以根据自己的要求做。 First write logic and only when you want to redirect then only check for the user type. 首先编写逻辑,并且仅在要重定向时才检查逻辑,然后仅检查用户类型。 This can also be done 这也可以做到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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