Is it possible to create more than one superusers in Django? When I create a new django app it automatically asks for creating a superuser. But I don't know how I can create more than one superuser to give admin access to other people ?
Use this command:
python manage.py createsuperuser
More: https://docs.djangoproject.com/en/dev/ref/django-admin/#createsuperuser
Related
I've added a field to my django model. Now, since I've had some instances of this model already, they not include this field resulting in django error page. I'm not able to manually delete those instances from admin panel.
I've searched that python manage.py flush is a way to go for reseting whole db, but I would like to delete only this particular model.
Is there a way to do this from the CLI ?
Solution:
For starting question, I accept #IainShelvington answer:
python manage.py shell
# then
from app_name.models import model_name
model_name.objects.all().delete()
Additionally, thanks to #AbdulAzizBarkat for providing:
python manage.py migrate <app_name> zero
After deploying my application the admin of the website does not work. I am able to use the website, create an account and do all the crud, but the admin does not work.
1 - I created the superuser with
python manage.py createsuperuser
2 - I deployed and tried to access the admin
https://djangotodowoo.herokuapp.com/admin
Although, every time that I try to access this page it redirects to:
https://djangotodowoo.herokuapp.com/admin/login/?next=/admin/
I am not sure if that's the problem, but it's a hint at least.
This is happening because I have on my settings.py the following line
LOGIN_URL = '/login'
That checks if someone is trying to access a page without login and redirects to the login page.
I am not sure what the problem actually is, any ideas on how to solve the issue?
Thank you very much folks!
I found out that everything was working locally, the reason I was not able to log into the admin with my admin account is that I have to create a superuser on the Heroku side as well.
The solution was:
Create Heroku Super User
heroku run python manage.py createsuperuser
I'm coding a web app with django and now I'm starting to handle users.
I'm trying to do the easy part, just create a new user throught admin interface, but when I try to do it I get a error and I don't find any info about it.
I enter django admin, log in with superuser, go to users, add user.
It only asks for: username and password.
When I submit changes then I get a NOT NULL constraint failed, this:
NOT NULL constraint failed: auth_user.last_login
I revised django documentation, and there it says to create a user like this:
from django.contrib.auth.models import User
user = User.objects.create_user('john', 'lennon#thebeatles.com', 'johnpassword')
So, I open a terminal, and do "./manage.py shell" "import django" "import User" and then I try this code, but fails too, it says:
NameError: name 'User' is not defined
Maybe I've changed something in the first part of the project? I've created models, templates, urls and used /static/ for references to files.
Thanks for your help!
last_login field changed in django 1.8. Just run the migrations
python manage.py migrate
Same issue, Had to run python manage.py migrate --fake and then python manage.py migrate and it worked perfectly.
In the app folder there is migration folder.. remove all files from it just keep pycache folder and init.py
then execute python manage.py migrate and then python manage.py makemigrations ..
simply we are removing the older migrations and migrating them again
I want to create a super user to log into the admin panel, I use to do this command:
python manage.py createsuperuser
I do not use ./manage.py syncdb (I use the South).
After creating a super user, I go to the address /admin/ and enter the data you gave when creating a super user and get an error if I typed bad data.
I am using Django 1.4.5 and accidentally deleted the superuser. How can I recreate the superuser account for an existing project? I found tutorials that show to do it when initially setting up a project but can't figure out how to create a superuser for an existing project.
I did try django-admin.py createsuperuser in the terminal without any luck
I apprecite the time and feedback.
You can invoke this command through manage.py
./manage.py createsuperuser