[Fixed]-Can't login to Django /admin interface

5👍

Not too sure on this, but syncdb might remove the superuser you just created. Try creating a superuser when syncdb prompts you to.

Otherwise, take a look at the user model in ./manage.py shell. Check User.objects.all()[0].is_superuser.

👤Ken

25👍

There is some kind of limitation in django-nonrel.

To create a superuser:

  • Stop the local webserver
  • Create the superuser

    python manage.py createsuperuser
    
  • Run the webserver again

    python manage.py runserver
    

8👍

Assuming you have the correct username and password, the only thing that will present the same behavior as a failed login is having is_staff=False for the user in question.

Go into your database and inspect the auth_user table. Make sure that is_staff is set to TRUE on the user you are using to log in.

5👍

In urls.py uncomment:

# Uncomment the next line to enable the admin:
**# url(r'^admin/', include(admin.site.urls)),**

and that should make you good for the races 🙂

PS. do not forget to run a ./manage.py syncdb and it will ask to setup an admin user.

👤BoGs

5👍

If you’re an idiot, like me, you might be trying to login with your email rather than your username.

I think I was doing this because when creating the superuser I remembered entering an email and not a username (because django offers you a username without having to type it), and perhaps the usual convention of using emails for usernames.. Man I feel stupid haha.

👤GP89

5👍

I had met the same situation just as you. And I found I switched the authentication backend to

someproject.backends.EmailCheckmodelBackend

And in the settings.py I had added a line:

AUTHENTICATION_BACKENDS = (‘someproject.backends.EmailCheckModelBackend’,)

And the backend is like:

class EmailCheckModelBackend(ModelBackend):
def authenticate(self, username = None, password = None, is_staff = None):
    try:
        user = User.objects.get(email = username)
        if user.check_password(password):
            if is_staff is not None:
                if user.is_staff == is_staff:
                    return user
                else:
                    return None
            return user

    except User.DoesNotExist:
        return None

You will find actually the username is forced to be alternated by ’email’. So you have to login your page with email account.
If like

Username: someone@somewhere.com

password: password

Then it works.
Hope this helpful for everyone.

0👍

I had the same problem and could not understand why I could not login because all the settings were correct. However, I traced it to Django offering me a superuser name containing an initial capital letter, but actually saving the name as completely lowercase!

I naturally used the superuser name with capitals (as offered by Django) and authentication failed. When inspecting the data tables to check ‘is_staff’ etc I spotted the error. I know I was not mistaken because I repeated the setup process a couple of times and noted the superuser credentials to be sure of details like case.

So, the moral is be careful when accepting the default name offered by Django! It lies!

0👍

In my case it was because I setup a Redis server

-1👍

It’s not that difficult to fix.
First of all make sure to allow your default settings

(DEBUG=TRUE,ALLOWED_HOST=[ ])

in the settings file of your website folder.

Get into your website folder (using the command prompt), and type the following command:

$ python manage.py createsuperuser
name:
email:e.g fulluser@admin.com
password:

Go back into the browser and run the server. Set the username (not the email), alongside your password which you created earlier. It will surely work fine this time.

Leave a comment