自己对参考链接中的代码进行了扩展,完整如下:
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 21:14:29)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> eml = "[email protected]"
>>> pw = "pass"
>>> uname = 'w2'
>>> from user.models import User
>>> user = User.objects.create_user(uname,eml,pw)
>>> user.save()
>>> user.check_password(pw)
True
>>> from django.contrib.auth import authenticate
>>> user = authenticate(username=uname, password=pw)
>>> user
<User: w2>