Admin page on django is broken

前端 未结 5 1038
你的背包
你的背包 2020-12-31 00:48

I\'ve set up a django project with an admin page. It worked perfectly for the first couple weeks of development, didn\'t use the admin page for a while, and when I came bac

相关标签:
5条回答
  • 2020-12-31 01:15

    You can do the following:

    • Enter your mysql (or other database console)
    • USE YourDATABASE;
    • SELECT * from auth_user;
    • watch is_staff and is_superuser item
    • UPDATE auth_user SET is_staff = "1" where username = "root";

    Then you can login again!

    0 讨论(0)
  • 2020-12-31 01:23

    Are you using a custom user model and forgot add it in settings.py? That is what just happened to me.

    # Substituting a custom User model
    
    AUTH_USER_MODEL = "app_custom_auth.User"
    
    0 讨论(0)
  • 2020-12-31 01:27

    This problem may be related to the Authentication Backends. Please check your settings files for the AUTHENTICATION_BACKENDS parameter.

    Try the following value:

    AUTHENTICATION_BACKENDS = (
        ('django.contrib.auth.backends.ModelBackend'),
    )
    

    More information on the Official Django Documentation

    0 讨论(0)
  • 2020-12-31 01:33

    I had the same issue, but AUTHENTICATION_BACKENDS flag on settings file was not the problem for me. Using Django Rest Framework somehow i had modified the password without calling set_password therefore bypassing hashing the password. That's why it was showing the invalid login.

    I was able to detect the issue by running simple test in order to test the user creation by a similar test:

    from django.test import TestCase
    
    from django.contrib import auth
    from .models import *
    
    class AuthTestCase(TestCase):
        def setUp(self):
            self.u = UserProfile.objects.create_user('test@dom.com', 'iamtest', 'pass')
            self.u.is_staff = True
            self.u.is_superuser = True
            self.u.is_active = True
            self.u.save()
    
        def testLogin(self):
            self.client.login(username='test@dom.com', password='pass')
    

    It is also worth mentioning that I was creating a custom user named UserProfile

    0 讨论(0)
  • 2020-12-31 01:34

    Try this; in tests.py:

    from django.contrib import auth
    
    class AuthTestCase(TestCase):
        def setUp(self):
            self.u = User.objects.create_user('test@dom.com', 'test@dom.com', 'pass')
            self.u.is_staff = True
            self.u.is_superuser = True
            self.u.is_active = True
            self.u.save()
    
        def testLogin(self):
            self.client.login(username='test@dom.com', password='pass')
    

    Then run the test with python manage.py test <your_app_name>.AuthTestCase. If this passes, the system is working, maybe look at the username and password to make sure they are acceptable.

    0 讨论(0)
提交回复
热议问题