1.User User Table default fields
Username,password,email,first_name,last_name
2. Adding User table Data
from Import User= User.objects.create_user ('mic','[email protected] ','micpassword') user.save ()
3. Create super users
Python3 manage.py Createsuperuser
To create a superuser, the difference between the users added above is that they are given permission to log in to the Django Admin Data Manager;
4. Modify User Password
Terminal modification: Python3 manage.py changepassword username New_password
Code modification;
admin background modification;
from Import User
U = User.objects.get (username="mic")uset_password (" zxcvbn123")u.save ()
5. User authentication
Django recommends using the LoginView view class to handle, rather than using the following example;
>>> fromDjango.contrib.auth.modelsImportUser>>> fromDjango.contrib.authImportAuthenticate>>>user = Authenticate (username="mic", password="zxcvbn123" )>>>User<User:mic>>>>ifUser: ...Print("Certification Success! ")... Certification Success! >>>user = Authenticate (username="mic", password="wrong_password " )>>> User
>>>
6. User groups and Permissions
Django comes with a user group table and a permission table, in addition, there are: user/user groups, users/permissions, user groups/Permissions These three additional generated many-to-many tables, namely the user, user group, the corresponding relationship of the permission ID;
How do you transplant permissions into your own backend management system?
is to change the list of the additions and deletions to check;
Django's own permission is the right to delete all tables and additions, if you need to set permissions on a single table, you need to construct ;
I want to add ...
User Authentication in Django | Python