Can't log in to admin site in Django
I was working through the polls tutorial and everything was fine until I tried to log in to the admin site; it just said
"Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive."
So I Googled the issue and tried everything I could. Here are all the problems I investigated:
- Database not synced: I synced it and nothing changed.
-
No
django_session
table: I checked; it's there. -
Problematic settings: The only change I made to the settings was the addition of
'polls.apps.PollsConfig',
toINSTALLED_APPS
. -
User not configured correctly:
is_staff
,is_superuser
, andis_active
are allTrue
. -
Old sessions: I checked the
django_session
table and it's empty. - Oversized message cookie: I checked and I don't even have one.
- Created superuser while running web server: I did this, but after stopping the web server, creating a new user, and restarting the web server, and trying to log in with the new user, it still didn't work.
-
Missing or wrong URL pattern: Currently I have
url(r"^admin/", admin.site.urls)
in mysite/urls.py. - Entering wrong username: The username I created was "admin" and that's the same one I'm typing in.
-
Wrong server command: I'm using
python manage.py runserver
. - Something wrong with database: I tried deleting the database and then reapplying the migrations, but nothing changed.
Is there anything I haven't tried yet, or am I missing something?
I guess you would have created this user through other ways and not python manage.py createsuperuser
This happens when you have two authentication systems. ie.,. you might have django inbuilt authentication and (for example) DRF token based authentication.
To login to the backend(django admin) you will have to use python manage.py createsuperuser
To change the pwd, use the below,
python manage.py changepassword
Sometimes the simplest solutions can solve huge problems. For me it was enough to comment out or delete:
SESSION_COOKIE_SECURE = True
That's all.