我想限制员工访问普通用户仪表板
def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
if user.is_active:
return redirect('admin')
esle:
login(request, user)
return redirect('users:home')
# Redirect to a success page.
...
else:
# Return an 'invalid login' error message.
...
我希望职员类型只能从管理面板登录,而他们不能访问用户仪表板。
答案 0 :(得分:0)
您需要在用户仪表板视图中设置限制,而不是在登录视图中进行更改。您可以这样做:
from django.contrib.auth.decorators import login_required
@login_required
def dashboard_view(request):
if request.user.is_staff or request.user.is_superuser:
return redirect('admin:index')
# rest of the logic