2017-09-08 8 views
1

を使用する方法私は、Djangoのユーザーを無効にし、それが働いていた、しかし、私は、これは私のmodel.pyあるDjangoのUserモデルの-overrideは、ログイン

username = 'test' 
password = '123' 
user = auth.authenticate(username = username, password = password) 
result = '' 

if user: 
    results = 'success' 
    auth.login(request,user) 
else: 
    result = 'fail' 
return render(request, 'login.html', locals()) 

ログインするauth.authenticateを使用することはできません

class User(AbstractUser): 
    qq = models.CharField(max_length=20) 

    class Meta: 
     verbose_name = 'Myuser' 
     def __str__(self): 
     return self.username 

、それが失敗を返すには、どのように私はこの1つを試してみてください

+0

テストはadminから作成し、私が作成したrootはそれを使用する場合はmakesuperuser –

+0

https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html – Robert

+0

Can is_activeフラグがFalseに設定されているユーザだけが起きているかどうかをチェックします。 – Swapnil

答えて

0
user = auth.authenticate(username=username, password=password) 
if user is not None: #to check whether user is available or not? 
# the password verified for the user 
    if user.is_active: 
     results = 'success' 
     auth.login(request,user) 
    else: 
     result = 'fail' 
else: 
# the authentication system was unable to verify the username and password 
    print("The username and password were incorrect.") 

のログインに使用することができます。それが働いているかどうか私に教えてください。

関連する問題