8
votes

I can't sign in to Django admin with any of the superusers I've created. Tried creating new superusers, changing passwords, etc. - no error messages for any of these processes, but still can't sign in.

I'm not sure if it's related, but I also can't run django-admin.py commands. Here is what I've done so far:

$ django-admin.py validate  
Error: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.  
$ export DJANGO_SETTINGS_MODULE=mysite.settings  
$ django-admin.py validate  
Error: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings

sys.path shows ['/Users/joerobinson/Sites/django/mysite' ... (other stuff on path)]

Is there something else I need to do to register the mysite module?

python manage.py runserver works fine.

Conclusion
For the question about logging in to django admin, I did not have django.contrib.auth.backends.ModelBackend included in my AUTHENTICATION_BACKENDS - adding this allowed me to sign in to admin.

I'm still working on the django-admin.py configuration question (which appears to not be related), and will reopen it in a separate question.

3
users must be staff members to login to admin. set is_staff = True for those user. - Evgeny
is_staff was set appropriately... same problem. - Joe
django-admin.py is not for running project-specific commands like validate. Use manage.py for that. - Daniel Roseman
Thanks for the tip. Am I correct in thinking DJANGO_SETTINGS_MODULE issue may be related to my inability to sign in to admin? Even after reseting passwords, creating new superusers, etc., I can't sign in. I can access the users in the shell and see that they're appropriately provisioned with privs, etc., but they don't seem to connect for admin. - Joe
Thanks for adding Conclusion part. It did the trick !! - Shashank Vivek

3 Answers

8
votes

In my case, I had "SESSION_COOKIE_SECURE = True" because I was trying SSL configurations. Just commenting this line worked.

7
votes

Well, to answer one of your questions, the parent folder of mysite is what needs to be on the python path. Adding mysite itself to your python path will expose the contents of mysite, not the mysite module to python.

As for runserver working / passwords not working, I haven't a clue. Have you customized anything with authentication?

Can you start the shell and try authenticating with your superuser? http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.authenticate

You said in a comment that "is_staff was set appropriately... same problem." -- does that mean you were able to log in with the first superuser to set is_staff??

5
votes

I ran into a similair problem but, I couldn't login on the admin interface even after removing the database and creating it from scratch. The problem was caused by a real silly mistake.

Don't run python manage.py testserver by accident. Make sure you use python manage.py runserver.