我正在使用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
);