How to reset Django admin password?

前端 未结 21 1704
遥遥无期
遥遥无期 2020-12-12 08:39

I am using Django (version 1.3) and have forgotten both admin username and password. How to reset both?

And is it possible to make a normal user into admin, and then

相关标签:
21条回答
  • 2020-12-12 09:40

    if you forget your admin then you need to create new user by using

    python manage.py createsuperuser <username>
    

    and for password there is CLI command changepassword for django to change user password

    python manage.py changepassword <username>
    

    OR

    django-admin changepassword <username>
    

    OR Run this code in Django env

    from django.contrib.auth.models import User
    u = User.objects.get(username='john')
    u.set_password('new password')
    u.save()
    
    0 讨论(0)
  • 2020-12-12 09:41
    1. python manage.py createsuperuser will create another superuser, you will be able to log into admin and rememder your username.
    2. Yes, why not.

    To give a normal user privileges, open a shell with python manage.py shell and try:

    from django.contrib.auth.models import User
    user = User.objects.get(username='normaluser')
    user.is_superuser = True
    user.save()
    
    0 讨论(0)
  • 2020-12-12 09:42

    This is very good question.

    python manage.py changepassword user_name

    Example :-

    python manage.py changepassword mickey
    
    0 讨论(0)
提交回复
热议问题