我在views.py中使用is_active标志等于false,因此非超级用户也可以登录,但不能正常工作。只有超级用户才能登录。
这是一些代码
登录逻辑视图:
List<FeePaymentStatusRequest> request =
monthlyFeePaymentList.stream()
.map(monthlyFeePayment -> new FeePaymentStatusRequest(monthlyFeePayment.getMonthlyFeePaymentId().toString(), "BGW"))
.collect(Collectors.toLis());
注册逻辑视图
def logingin(request):
if request.method == 'POST':
username = request.POST.get('username','')
password = request.POST.get('password','')
user = auth.authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('/')
else:
return redirect('/signup')
return render(request, 'login.html')
我希望所有用户都可以登录
答案 0 :(得分:2)
By definition,is_active
标志用于阻止用户登录。如果希望所有用户都可以登录,请不要将其设置为false。
答案 1 :(得分:0)
设置is_active = True
如果将is_active设置为flag,则表示该用户已被禁用。如果我们不希望用户从数据库中删除并尊重外键约束,则禁用用户帮助。
def signup(request):
if request.method == 'POST':
user_name = request.POST.get('user_name','')
first_name = request.POST.get('first_name','')
last_name = request.POST.get('last_name','')
email = request.POST.get('email','')
password = request.POST.get('password','')
if User.objects.filter(email=email).exists():
messages.error(request, 'E-Mail Already Exist Please Use Different Email')
else:
user = User.objects.create_user(user_name, email, password)
user.is_active = True
user.first_name = first_name
user.last_name = last_name
user.save()
return render(request, 'signup.html')