Disclaimer: The login and logout function of this blog will use django-allauth. Reference resources are: django-allauth documentation django-allauth tutorial

1.Install django – allauth

pip install django-allauth

2,Configuration information

After installation, set blog/settings.py and add allauth-related apps to INSTALLED_APP.

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django. Contrib. Sessions',' the django. Contrib. The messages' and 'django. Contrib. Staticfiles' # < add storm related applications >' storm ', # > 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.github', # <allauth--end---> ]

Note: Allauth has a dependency on django.contrib.sites, so you must also add it and set SITE_ID

There is no need to go into SITE_ID as it does not involve multiple sites at this time. For now, the SITE_ID value needs to be changed when the “SocialApp Matching Query Does Not Exist “error occurs

3,Allauth basic Settings

Django.contrib. sites. # SITE_ID Specifies the database ID of the Site object associated with a particular configuration file. When matching query does not exist, you will need to change the SITE_ID = 1 page if you have logged in and registered. The default is /accounts/profile/ LOGIN_REDIRECT_URL = "/" Select username or email ACCOUNT_AUTHENTICATION_METHOD = "username_email" # set email address ACCOUNT_EMAIL_REQUIRED = True for user registration # log out and log out You don't need to verify that ACCOUNT_LOGOUT_ON_GET = TRUE

4,Django-allauth common Settings

You can also add other Settings to achieve the desired functionality, such as setting an email confirmation expiration date and limiting the duration of a user logging in with an incorrect password.

# assigned to use login method (user name, email address, or both) ACCOUNT_AUTHENTICATION_METHOD (= "username" | "email" | "username_email") # mail confirmation mail deadline (days) Account_email_confirmation_expire_days (=3) # Email validation method in registration: one of "Mandatory", "Optional" or "None" Account_email_verification (="optional") # Account_email_confirmation_cooldown (=180) # Number of failed login attempts Account_email_confirmation_cooldown (=180 Attempts_Attempts_Timeout (=300) # changed to True for the duration of original operation for which the user was prevented from attempting to original operation for original operation for which it failed. Once users confirm their email address, ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION (=False) # ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE (=False) # Account_login_on_password_reset (=False) # Control the life of the session, Also optional :False,True ACCOUNT_SESSION_REMEMBER (=None) # Account_signup_email_enter_twice (=False) # Do you need to enter the email account twice when registering ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE (=True) # ACCOUNT_USERNAME_BLACKLIST (=[]) # Account_username_blacklist (=[]) # Enforce the uniqueness of email addresses ACCOUNT_UNIQUE_EMAIL (=True) # integer ACCOUNT_USERNAME_MIN_LENGTH (=1) # for the minimum length allowed for a user name Use the fields retrieved from the social account provider (such as user name, mail) to bypass the registration form socialaccount_auto_signUp (=True) # set the LOGIN_REDIRECT_URL (="/") # set the LOGIN_REDIRECT_URL (="/") # set the logout link ACCOUNT_LOGOUT_REDIRECT_URL (="/")

5,Configure the allauth route

urlpatterns = [
    url(r'^admin/', admin.site.urls),

    # allauth
    url(r'^accounts/', include('allauth.urls')),

    # storm
    url('', include('storm.urls', namespace='blog')),  # blog
]

6,Running effect

Which route you can access depends on the allauth Settings in blog/settings.py

registered

http://127.0.0.1:8080/accounts/signup/

The login

http://127.0.0.1:8080/accounts/login/

7,Django-allauth all routes

Below are all of django_allauth’s built-in URLs, which are accessible. You can check it out at allauth/account/urls.py

# # login/accounts/login/registration/accounts/signup / # reset password/accounts/password reset / / accounts/logout / # # logged on a password # / accounts/password/set/change the password (login required)/accounts/password/change / # users can add and remove email, And verify/accounts/email / # management escrow account/accounts/social/connections

User details are not available

/accounts/profile/

What if I want the user to provide more information when registering (such as company name, phone number, address, etc.) What if the user needs to modify their personal information after registering? This view and URL are not provided because each developer has different needs for additional information that the user needs to provide. Therefore, django-allauth does not provide a user-specific application

Five | user details, please refer to: [personal blog users’ personal information Profile extension]