User Authentication in Django | Python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.