django,仅针对用户而非超级用户进行身份验证

时间:2019-12-20 19:59:17

标签: python django

我正在使用Django> = 3.0,如何创建仅允许非超级用户使用的身份验证。我目前正在登录部分,普通用户可以登录,但对于那些被标记为is_superuser = True

的用户严格
def request(request):

    if len(request.POST) > 0 :

       # print(request.__class__.__name__);

       constraint = helpers.constraint(request);
       data = constraint.strict(["username", "password"], True);

       username = data['username'];
       password = data['password'];

       user = auth.authenticate(
           username = username,
           password = password
       );

       if user :
           print(user);
           breakpoint();

           auth.login(request,user)

           return HttpResponse("jkjhhj");

       messages.info(request, "Invalid credentials");

    return login(request); 

与此类似。...

user = auth.authenticate(
               username = username,
               password = password,
               is_superuser = False
           );

0 个答案:

没有答案