0

Before i go forward, I know this is a commonly asked question but I have searched the top questions related to this, and none of it seems to be helping..

Following: https://docs.djangoproject.com/en/2.2/intro/tutorial02/

What I have done:

py manage.py createsuperuser

Created user

I have confirmed the user is a superuser with:

from django.contrib.auth.models import User
active_staff = User.objects.filter(is_active=True, is_staff=True)

This will then list the super users

Although, when I do something like:

u = User(username="admin") u.is_staff False u.is_superuser False

Why is this?

I also then manually set to true, save(), then check, and it's now True. Try to log in, doesn't work. restart shell and check, it's back to false.

I tried the accepted answer here: Can't login to django admin after creating a super user with a custom user model

This: Admin page on django is broken

None have helped.

If there is anything i need to copy/paste from my Djnago app to help, pleaes let me know. I am new with Python and Django so I'm not exactly sure what to add to this question.

uno
  • 1,421
  • 12
  • 38

3 Answers3

2

for having a superuser you only have to use manage.py createsuperuser command,and by using this command,you are doing:

    User(is_superuser=True,**kwargs)

so can you explain that what error exactly you see when you wanna login to admin panel?

Erfan
  • 379
  • 1
  • 6
  • Error:Please enter a correct username and password. Note that both fields are case-sensitive. ... This is just the notice. there are no other errors to my knowledge in the console. Just shows the GET and POST – uno Oct 28 '19 at 10:11
1
u = User(username="admin")

This is just initializing a new User Object and not querying the database. It will always return False for is_staff and superuser, as False if their default Value. Try querying the database using -

u = User.objects.get(username="admin")

to check the values of the flags.

Saurabh Sangwan
  • 417
  • 2
  • 6
  • Oh okay well that makes sense now why is was false. I just checked manually and everything is True for superuser and staff – uno Oct 28 '19 at 03:10
1

Well, I am unsure how this is possible..

I have been creating the app in the directory d/programming/mysite with success... creating files, migrations etc.

I just checked and the app within the project is really in d/programming/django/mysite... i went ahead and created a user from there and it worked.

I'm a bit confused on how this is happening but I'm sure I'm wrong somehow and somewherea

uno
  • 1,421
  • 12
  • 38