我正在使用Django(1.3版),忘记了管理员用户名和密码。如何重置两者?

是否可以将普通用户变为管理员,然后删除管理员状态?


当前回答

这是一个很好的问题。

Python manage.py changepassword user_name

例子:-

python manage.py changepassword mickey

其他回答

python manage.py changepassword <user_name>

看文档

你也可能回答了一个错误的设置问题,没有工作人员。在这种情况下,前往postgres:

obvioustest=# \c [yourdatabasename]
obvioustest=# \x
obvioustest=# select * from auth_user;
-[ RECORD 1 ]+-------------
id           | 1
is_superuser | f
is_staff     | f
...

要修复,直接编辑:

update auth_user set is_staff='true' where id=1;

只需在命令行中输入以下命令:

python manage.py changepassword yourusername

如果在/admin/网站需要一个reset_password链接,这是去的方式: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#adding-a-password-reset-feature

可使用createsuperuser命令创建新的超级用户。