nana
nana

Reputation: 4481

Can't login to Django /admin interface

First of all, I am a newbie. I'm running Ubuntu 11.04 which comes with Python 2.7 so I installed Python2.5 in different dir to run Django-Non-Rel on Google App Engine. I did the Guestbook tutorial and now I am trying to add admin access but when I type in correct username:password Django thinks its incorrect. It doesn't even work when deployed to GAE. If you know please poke me in the right direction.

I added:

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

INSTALLED_APPS = (
    ...
    'django.contrib.admin',
    ....
)

EDIT
I also added

url(r'^admin/', include(admin.site.urls)),

to urls.py in subproject directory.
EOEDIT

Then I created superuser and synced databases:

> python2.5 xxx-xxx-guestbook/manage.py createsuperuser python2.5
> xxx-xxx-guestbook/manage.py syncdb

Then ran the app and can't login. I created multiple different supersusers always with the same result.

EDIT2

Thanks everyone for trying to help but unfortunately neither of the offered solutions fixed the problem. I have decided to first learn Django on its own and then maybe switch to GAE Django-nonrel, so the question is not relevant anymore. Should I still pick one answer to give someone some points?

Upvotes: 21

Views: 44573

Answers (9)

daniel mandelblat
daniel mandelblat

Reputation: 7

In my case it was because I setup a Redis server

Upvotes: 0

leong_geek
leong_geek

Reputation: 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 [email protected]
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.

Upvotes: -1

dotslash
dotslash

Reputation: 381

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: [email protected]

password: password

Then it works. Hope this helpful for everyone.

Upvotes: 5

GP89
GP89

Reputation: 6740

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.

Upvotes: 5

Ken
Ken

Reputation: 702

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.

Upvotes: 5

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
    

Upvotes: 26

Tarquin
Tarquin

Reputation: 41

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!

Upvotes: 0

Chris Pratt
Chris Pratt

Reputation: 239430

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.

Upvotes: 8

BoGs
BoGs

Reputation: 83

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.

Upvotes: 5

Related Questions