English 中文(简体)
如何重定Django的行政密码?
原标题:How to reset Django admin password?

我正在使用Django(第1.3版),并忘记了行政用户名称和密码。 如何重新确定两者?

能否让普通用户进入行政管理,然后取消行政地位?

最佳回答
python manage.py changepassword <user_name>

,见

问题回答
  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.

给予普通用户特权,可使用<代码>python管理。 py shell andtries:

from django.contrib.auth.models import User
user = User.objects.get(username= normaluser )
user.is_superuser = True
user.save()

You may try through console:

python manage.py shell

接着,在壳体中使用文字

from django.contrib.auth.models import User
User.objects.filter(is_superuser=True)

将把所有超级用户列入名单。 1. 如果您从名单上确认用户名称:

usr = User.objects.get(username= your username )
usr.set_password( raw password )
usr.save()

您提出了新的前言:

https://docs.djangoproject.com/en/dev/ref/django-admin/? from=olddocs#django-admin-createsuperuser"createsuperuser 指挥。

这是一个很好的问题。

python Manager.py changepassworduser_name

例:

python manage.py changepassword mickey

检索用户名和密码的最佳途径之一是浏览和更新。 用户模式提供了这样做的完美方式。

In this case, I m using Django 1.9

  1. 根基目录,即你“管理.py”档案的所在地是使用你的ole子或其他应用,如Gite。

  2. 利用“python管理.py Shell”的指挥将沙尔遣返。

  3. Import the User Model by typing the following command "from django.contrib.auth.models import User"

  4. Get all the users by typing the following command "users = User.objects.all()"

  5. Print a list of the users For Python 2 users use the command "print users" For Python 3 users use the command "print(users)" The first user is usually the admin.

  6. Select the user you wish to change their password e.g.

    <代码>用户=用户[0]

  7. 密码

    user.set_password (0) 姓名_of_the_new_password_for_user_s selected

  8. 删除新的密码

    <代码>用户。

在使用用户名称和最新密码时开始服务器和标识。

new setup should first run python manage.py createsuperuser to create user. It seems like there is no default username password to login into admin.

Two ways to do this:

www.un.org/Depts/DGACM/index_french.htm

(env) $ python manage.py changepassword <username>

或(在几个答复的基础上扩大,但为任何扩展用户模式开展工作)使用<<>django-admin ll:

(env) $ python manage.py shell

This should bring up the shell command prompt as follows:

Python 3.7.2 (default, Mar 27 2019, 08:44:46) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>

那么,你们会想:

>>> from django.contrib.auth import get_user_model
>>> User = get_user_model()
>>> user = User.objects.get(username= admin@hug.com )
>>> user.set_password( new password )
>>> user.save()
>>> exit()

N.B. Why have I answered this question with this answer?

Because, as mentioned, User = get_user_model() will work for your own custom User models. Using from django.contrib.auth.models import User then User.objects.get(username= username ) may throw the following error:

AttributeError: Manager isn t available;  auth.User  has been swapped for  users.User 
python manage.py changepassword username

You may try this:

1.Change Superuser password without console

python manage.py changepassword <username>

2.Change Superuser password through console

enter image description here enter image description here

你或许也回答了一个定点问题,有零工作人员。 在这种情形下,应负责:

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;

如果您愿意创建行政管理用户,首先就在<代码>createsuperuser的指挥下建立。 然后修改密码。

如果你忘记你的管理,你需要利用你来创造新的用户。

python manage.py createsuperuser <username>

为改变用户密码,CLI指令changeword

python manage.py changepassword <username>

页: 1

django-admin changepassword <username>

页: 1 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()

If you re using custom user model

(venv)your_prj $ ./manage.py shell
>>> from customusers.models import CustomUser
>>> CustomUser.objects.filter(is_superuser=True)
>>> user = CustomUser.objects.get(email="somesuper@sys.com")
>>> user.set_password( @NewPwd )
>>> user.save()
>>> exit()

如果你不知道这里产生的用户名称。 如上文所述,你可以接触用户。

python manage.py shell 
from django.contrib.auth.models import User
usrs = User.objects.filter(is_superuser=True)
#identify the user
your_user = usrs.filter(username="yourusername")[0]
#youruser = usrs.get(username="yourusername")
#then set the password

However in the event that you created your independent user model. A simple case is when you want to use email as a username instead of the default user name. In which case your user model lives somewhere such as your_accounts_app.models then the above solution wont work. In this case you can instead use the get_user_model method

from django.contrib.auth import get_user_model 
super_users = get_user_model().objects.filter(is_superuser=True)
#proceed to get identify your user
# and set their user password

值得注意的另一件事是将用户位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位位。 这至少使我受益。 详细情况是,我设立了另一个<代码>超级用户,如上所述。 然后,我去查阅数据库表auth_user,并查询该用户名称以确保其is_staff。 国旗为1。 这最后使我得以登录在<代码>admin的网站上。

Create a new superuser with the command "python manage.py createsuperuser". Login as the new super user. Click on the users link. Then click on the user you want to delete. click on delete user at the end of the form page.

注: 上述程序将对特定用户进行的活动记录进行修改。

最好的办法只是去找您的终点站和类型。

python manage.py createsuperuser

and insert another password and user name again but u will lost some of your profile that u have created before in most cases.

在你的指挥线上,这种指挥是公正的:

python manage.py changepassword yourusername

use

python manage.py dumpdata

then look at the end you will find the user name

I think,The better way At the command line

python manage.py createsuperuser

If a reset_password link is needed in the /admin/ website this is the way to go: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#adding-a-password-reset-feature





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....

热门标签