3

I created a project in django and the first thing I want to do is to create a superuser for admin account and then proceed with the django project but the problem is after creating a superuser account using

python manage.py createsuperuser

and filling out the information the superuser gets created it says

Superuser created successfully.

But when I try to login with these credentials it says

Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive.

I am not sure if there is some other setting that I need to check out or I am doing something wrong.

Please suggest me solution for that.

vikram
  • 361
  • 5
  • 15

3 Answers3

2

Go to the python shell:

python manage.py shell

In the python console, run the following:

from django.contrib.auth.models import User

user = User.objects.get(username='your_username') # enter inside the quotes the username you entered when you ran python manage.py createsuperuser
user.set_password('new_password') # change the password 
user.is_superuser = True
user.is_staff = True
user.save()

exit()

Then try to login again using the credentials you set.

Victor
  • 2,864
  • 1
  • 12
  • 20
1

Did you run python manage.py migrate before you ran python manage.py createsuperuser? During createsuperuser process, you need the username and password, you don't need anything else, i.e. email.

You should do this first, then run python manage.py runserver

lastly, navigate to http://127.0.0.1:8000/admin/

There really isn't anything else you would need to do. If you are getting another error, please post it.

ja408
  • 798
  • 5
  • 16
0

I had similar problems too but by doing as follows it worked fine.

def create_superuser(self, username, email, password=None, **extra_fields):
    user = self.create_user(username, email, password=password, is_staff=True, **extra_fields)
    user.is_active = True
    user.save(using=self._db)
    return